Migrate from react-redux 5 to 6 on: Solution for dynamically injecting sagas and reducers #1821
iamgiolaga
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Yeah, that's the switch from React's legacy context API ( As of 7.1, we now officially document a https://react-redux.js.org/using-react-redux/accessing-store#using-the-usestore-hook Also, accessing |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I spent the last weekend figuring out how to migrate from react-redux 5.0.0 to 7.2.5 without breaking the dynamic injection of sagas and reducers.
I don't know if my use case was too specific, but I didn't find a solution online; since I was enough lucky to get it, I put it here hoping that this can be helpful for someone else:
the problem was caused by the visibility change that redux store had through the connected components during this migration.
My code was of the form:
and in my connected component, let's say
Login
, I hadin particular the problem was related to
withSaga
andwithReducer
, respectively withinjectSaga
andinjectReducer
calls, where in both cases I was able to access the redux store throughthis.context.store
in order to get the injectors.After upgrading to react-redux 7.2.5 (and in general, this occurs after 6.0.0), this kind of access doesn't work anymore and returns undefined, because context is an empty object.
The solution for me was to
React.createContext
and pass the store as parameterthis.context.store
this.context.store
withCustomContext._currentValue
I am not a react-redux expert, so I could have made some trivial mistakes, but I hope that this works for you too!
Beta Was this translation helpful? Give feedback.
All reactions