1
votes

I'm getting this error and I googled solutions, but it seems like everything should be set up correctly.

Full error is: "Invariant Violation: Could not find "store" in the context of "Connect(AppComponent)". Either wrap root component in a , or pass a custom React context provider to and the corresponding React context consumer to Connect(AppComponent) in connect options.

This error is located at: in Connect(AppComponent) (at renderApplication.js:34) in RCTView (at View.js:45) in View (at AppContainer.js:98) in RCTView (at View.js:45) in View (at AppContainer.js:115) in AppContainer (at renderApplication.js:33)

This is my code:

index.js

import { Provider } from 'react-redux'
import { createStore } from 'redux';

import App from './app/App';
import appState from './app/redux/reducers';

import {name as appName} from './app.json';

let store = createStore(appState);
export default class AppRoot extends Component {
  render() {
    return (
      <Provider store={store}>
        <App/>
      </Provider>
    );
  }
}

AppRegistry.registerComponent(appName, () => App);

App.js

//import...

class AppComponent extends Component {
  //code..
}

const mapStateToProps = (state, props) => {
  return {}
};

const mapDispatchToProps = (dispatch, props) => {
  return {
    onFavoriteChange: (id, type) => {
      switch(type){
        //cases...
      }
    }
  }
};

const App = connect(
  mapStateToProps,
  mapDispatchToProps
)(AppComponent);

export default App;

index.js (in /reducers)

import { combineReducers } from 'redux';

//imports...

let appState = combineReducers({
    //all import...
});

export default appState;
1

1 Answers

1
votes

The App component that is registered at the root is not AppRoot. It means that React render App without a Provider to provide the store. Then the connect HOC throws an error. You have to update the call to:

AppRegistry.registerComponent(appName, () => AppRoot);