在“连接”的上下文中找不到“商店”

时间:2020-01-31 15:58:47

标签: reactjs react-native redux react-navigation

我正在从“反应导航”:“ ^ 3.0.9”>“反应导航”:“ ^ 4.1.0”升级

我收到此错误:

永久违反:在“ Connect(HomeScreen)”的上下文中找不到“ store”。可以将根组件包装在中,也可以在连接选项中将自定义的React上下文提供程序传递给Connect(HomeScreen)并将相应的React上下文使用者传递给Connect(HomeScreen)。

app.tsx:

import NavigationService from './navigation/NavigationService';
import {connect} from 'react-redux';
import SplashScreen from 'react-native-splash-screen';
import {store, persistor} from './config/configureStore';
import {PersistGate} from 'redux-persist/integration/react';
import AppNavigator from './navigation/AppNavigator';
class App extends React.Component {
  componentDidMount() {
    // SplashScreen.hides();
  }
  render() {
    const {videos} = this.props;

    return (
      ..
        <PersistGate loading={null} persistor={persistor}>
          <AppNavigator
            ref={navigatorRef => {
              NavigationService.setTopLevelNavigator(navigatorRef);
            }}
          />
        </PersistGate>...
    );
  }
}

export default App;

主屏幕:

class HomeScreen extends React.Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    const {fetchData} = this.props;
    fetchData();
  }

  render() {
    const {videos} = this.props;

    return (
      <View style={styles.container}>
        <HomeMenu {...this.props} />
      </View>
    );
  }
}

const mapDispatchToProps = dispatch => ({
  fetchData: () => dispatch(fetchData()),
});
const mapStateToProps = state => {
  return {
    videos: state.tcApp.videos,
  };
};
export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(HomeScreen);

AppNavigator:

..
const config = {
    ..
};

const withHeader = (
    screen: Function,
    routeName: string,
    Header,
): StackNavigator =>
    createStackNavigator(
        {
            [routeName]: {
                screen,
                navigationOptions: ({routeName, props}) => ({
                    header: props => <Header {...props} />,
                }),
            },
        },
        {
            initialRoute: 'Home',
            cardStyle: {
                backgroundColor: 'transparent',
                opacity: 1,
            },
            transitionConfig: () => ({
                containerStyle: {
                    backgroundColor: 'transparent',
                },
            }),
        },
    );

const routes = {
    ...
};

const NestedDrawer = createDrawerNavigator(routes, config);

const MainStack = createStackNavigator(
    {
        Home: {
            screen: HomeScreen,
            navigationOptions: ({props}) => ({
                header: props => <HomeHeader {...props} />,
            }),
        },
    ...
    },
    {
    ....
    },
);

export default createAppContainer(MainStack);

我收到以下错误:

0 个答案:

没有答案