Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

javascript - i am unable to connect my component to store in react native throwing the error as Could not find "store" in the context of "Connect(App)"

Hello here i am facing an issue while i am connecting my component to store, it is throwing an error as i am new to react native please help me how to resolve this error.

i also have tried downgrade of the versions but no luck,below are the versions of respected libraries.

 "react-redux": "^7.2.2",
    "redux": "^4.0.5",
    "redux-persist": "^5.6.12",
    "redux-thunk": "^2.3.0"

below is my App.js file

import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import AuthNavigator from "./app/navigation/authNavigator";
import DashboarNavigator from "./app/navigation/dashBoardNavigator";
import navigationTheme from "./app/navigation/navigationTheme";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import { persistStore, persistReducer } from "redux-persist";
import storage from "redux-persist/lib/storage";
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
import { PersistGate } from "redux-persist/lib/integration/react";
import { userReducer } from "./app/store/reducers/index";
import thunk from "redux-thunk";
import { Autherization } from "./app/authentication/AuthComponent";
import { connect } from "react-redux";
const persistConfig = {
  key: "root",
  storage: storage,
  stateReconciler: autoMergeLevel2
};
const pReducer = persistReducer(persistConfig, userReducer);
const store = createStore(pReducer, applyMiddleware(thunk));
const persistor = persistStore(store);

function App(props) {
  console.log(props, "kkkkkkk", store.getState());
  return (
    <Provider store={store}>
      <PersistGate persistor={persistor}>
        <NavigationContainer theme={navigationTheme}>
          <Autherization />
          {/* {props && props.user && props.user.token ? (
              <DashBoardNavigator />
            ) : (
              <AuthNavigator />
            )} */}
        </NavigationContainer>
      </PersistGate>
    </Provider>
  );
}
const mapStateToProps = state => {
  return {
    ...state,
    user: state.user,
    token: state.user ? state.user.access_token : null
  };
};
const AppPage = connect(mapStateToProps)(App);
export default AppPage;
export { store };
`
question from:https://stackoverflow.com/questions/65936323/i-am-unable-to-connect-my-component-to-store-in-react-native-throwing-the-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...