我遇到一个奇怪的问题,当我export
a const
到另一个js文件。这是我的问题:React原生JSX导出导入标识
想象一下,我有两个文件index.js
和router.js
。
// in router.js
export const stackNav = StackNavigator({
Home: {
screen: Me,
navigationOptions: {
title: 'Welcome'
}
}
});
// in index.js
import { stackNav } from './router';
class MainApp extends Component {
render() {
return (
<stackNav />
);
}
}
export default MainApp;
当我用上面的代码运行,我无法运行我的应用程序,它显示红色屏幕上的错误消息:Expected a component class, got [object Object].
但是,如果我改变所有stackNav
到StackNav
,我可以运行我的应用成功。所以,我不知道为什么名称/标识符的情况很重要?
这将会回答你的问题[https://stackoverflow.com/questions/30373343/reactjs-component-names-must-begin-with-capital-letters](https://stackoverflow.com/questions/30373343/reactjs-component-names-must-begin-with-capital-letters) –
@NeelGala您的评论对我的问题是正确的答案,我的问题与您提供的线索重复。 – bufferoverflow76