Inject Reducer (create reducers on demand)
See original GitHub issuehi. I’m using this library with saga and its woriking nice, now I want to add reducers on api requests but couldn’t make it here is my configs:
export const makeStore = (context) => {
let sagaMiddleware = createSagaMiddleware();
let storeWithSaga = createStore(createReducer(), context, applyMiddleware(sagaMiddleware));
storeWithSaga.sagaTask = sagaMiddleware.run(rootSaga)
return storeWithSaga; // 4: now return the store:
};
export const wrapper = createWrapper(makeStore, { debug: true });
export function createReducer(asyncReducers) {
return combineReducers({
userReducer,
themeReducer,
...asyncReducers,
});
}
class TestProject extends App {
static getInitialProps = async ({ Component, ctx }) => {
const pageProps = {
// 1. Wait for all page actions to dispatch
...(Component.getInitialProps ? await Component.getInitialProps(ctx) : {}),
};
if (ctx.req) {
// 2. Stop the saga if on server
ctx.store.dispatch(END);
await ctx.store.sagaTask.toPromise();
}
return {
// 3. Return props
pageProps,
};
};
render() {
const { Component, pageProps } = this.props;
return (
<>
<Layout>
<Component {...pageProps} />
</Layout>
</>
);
}
}
export default wrapper.withRedux(appWithTranslation(TestProject ));
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Code Splitting | Redux
To code split with Redux, we want to be able to dynamically add reducers to the store. However, Redux really only has a...
Read more >Redux: Injecting reducers dynamically | by Matheus Monteiro
Redux provides a function called createStore, which alongside with the combineReducers functions, allows us to integrate our reducers functions.
Read more >How to dynamically load reducers for code splitting in a Redux ...
Do not combine reducers. Instead put them in a (nested) object of functions as you would normally but without combining them. · Use...
Read more >Dynamic inject Reducer - use your Reducer on demand
Redux give us a function combineReducer to combine all reducers to only one, and use it as parameter to create redux store.
Read more >Dynamically load reducers for code splitting in a ... - Tan Li Hau
inducer (read: Inject Reducer) gives you a HOC that will add you reducer to the Redux store that is currently using during componentWillMount ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
All reducers must be static and synchronous. Primarily because their behavior must be deterministic, if you don’t want to end up with inconsistent state because some reducers weren’t loaded beforehand.
now I have created reducer in ssr but cant pass it to csr