【发布时间】:2018-09-12 21:47:12
【问题描述】:
我正在尝试导出初始组件,但我一直收到Invariant Violation 错误:
有没有更好的方法来导出我的 HMAPP 组件并将其导入 App.js 中?
错误图片: Error screen
这是我的 App.js:
import HMAPP from './app/HMAPP';
export default HMAPP;
这是我的 HMAPP 组件:
import { Provider } from 'react-redux';
import { persistStore } from 'redux-persist';
import { Navigation } from 'react-native-navigation';
import Mapbox from '@mapbox/react-native-mapbox-gl';
import { registerScreens } from './screens';
import store from './store/configureStore';
import { appInit, getInitialScreen } from './appInit';
import { handleErrorObject } from './lib/handleError';
Mapbox.setAccessToken('pkaeda324234');
const persistor = persistStore(
store,
null,
() => {
registerScreens(store, Provider);
appInit(store)
.then(() => {
const initialScreen = getInitialScreen(store.getState());
Navigation.startSingleScreenApp({
screen: {
screen: initialScreen,
},
passProps: {
persistor,
},
drawer: {
left: {
screen: 'DrawerMenuScreen',
},
},
appStyle: {
orientation: 'portrait',
},
});
})
.catch((error) => {
handleErrorObject('Error initializing app', error);
});
},
);
【问题讨论】:
-
您是否从
./app/HMAPP导出任何内容? -
不,它只是用于持久存储和初始导航
-
如果没有导出,您如何尝试导入任何内容?
-
我正在尝试查找其他人制作的错误。当它不是组件时如何导出它,它只是常量。如果你有,你可以检查代码并给出解决方案
-
您可以导出变量(
const或其他变量)并再次导入。这是常规的 Javascript。这取决于你如何使用这个变量。在错误中,它清楚地表明这是一个出口问题。我不知道你打算如何使用它,但 React 等待正确的导出/导入,你在哪里使用它。
标签: reactjs react-native