我收到无法正确导出或正确导入组件的错误。而且只有当我从redux添加Provider标签时才会发生这种情况。我还检查了动作,Reducer,并且类型和所有内容都没有默认值导出,因此所有内容都用大括号导入。
错误:元素类型无效,预期为字符串(对于内置组件)或类/函数,但未定义。
App组件:
import React from 'react';
import {NavigationContainer, DarkTheme} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import {Providor} from 'react-redux';
import {createStore, applyMiddleware} from 'redux';
import {showCounries} from '../Reducers/Reducer';
import ReduxThunk from 'redux-thunk';
import Worldclass from './Worldclass.js';
import 'react-native-gesture-handler';
const store = createStore(showCounries, applyMiddleware(ReduxThunk));
const Stack = createStackNavigator();
// eslint-disable-next-line no-undef
const App = () => {
return (
<Providor store={store}>
<NavigationContainer theme={DarkTheme}>
<Stack.Navigator initialRouteName="worldclass">
<Stack.Screen
name="worldclass"
component={Worldclass}
options={{title: 'World Class'}}
/>
</Stack.Navigator>
</NavigationContainer>
</Providor>
);
};
export default App;
世界级:
import React from 'react';
import {
ActivityIndicator,
StyleSheet,
FlatList,
View,
SafeAreaView,
StatusBar,
} from 'react-native';
import {connect} from 'react-redux';
import {fetchCountires} from '../Actions/Action.js';
const mapStateToProps = state => {
return {
countriesList: state.fetchCountriesList.countriesList,
loading: state.fetchCountriesList.loading,
error: state.fetchCountriesList.error,
};
};
const Worldclass = props => {
const loadingFunc = () => {
return props.loading ? (
<View style={styles.bigMarginTop}>
<ActivityIndicator size="large" />
</View>
) : (
<View />
);
};
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView style={styles.container}>
{loadingFunc()}
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
borderTopWidth: 1,
borderColor: 'white',
flexDirection: 'column',
backgroundColor: '#2d2d2d',
},
bigMarginTop: {
marginTop: 50,
},
});
export default connect(
mapStateToProps,
null,
)(Worldclass);
和索引文件:
import {AppRegistry} from 'react-native';
import App from './src/Containers/App';
import {name as appName} from './app.json';
AppRegistry.registerComponent(appName, () => App);
有人知道为什么会这样吗?
谢谢,
在这里看看:https://react-redux.js.org/api/provider
[import {Providor} from 'react-redux';
应该是import {Provider} from 'react-redux';
也<Providor store={store}>
应为<Provider store={store}>
,</Providor>
应为</Provider>
这是我马上看到的问题。如果仍不能解决问题,请通知我,我将再进行研究。