Search code examples
reactjsredux

What to provide for "store" attribute in <Provider store="" > while working with Redux-store?


Root component need to be wrapped inside like,

<Provider store= >
   <App />
</Provider>

But, I am not sure about what to provide in store attribute. Could anybody let me know this?


Solution

  • I usually use it to store all reducer like this.

    index.js

    import { Provider, connect } from 'react-redux';
    import ReduxThunk from 'redux-thunk';
    import { createStore, applyMiddleware } from 'redux';
    import reducers from './reducers';
    
    const createStoreWithMiddleware = applyMiddleware(ReduxThunk)(createStore);
    const store = createStoreWithMiddleware(reducers);
    
    <Provider store={store}>
       {/*routers here*/}
    </Provider>
    

    reducers.js

    import { combineReducers } from 'redux-immutable';
    
    // reducers import
    import MainReducer from './containers/Main/reducer';
    import RegisterReducer from './containers/Register/reducer';
    import ChangePasswordReducer from './containers/ChangePassword/reducer';
    
    const reducers = combineReducers({
        main: MainReducer,
        register: RegisterReducer,
        changePassword: ChangePasswordReducer
    })
    
    
    export default reducers;