question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inject Reducer (create reducers on demand)

See original GitHub issue

hi. 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kirill-konshincommented, Dec 24, 2020

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.

0reactions
jamal-rahimzadegancommented, Jan 1, 2021

now I have created reducer in ssr but cant pass it to csr

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found