React 16.13 throws a warning when "nesting" useInjectReducer calls
See original GitHub issueAfter upgrading to React 16.13, we started getting this warning in many places:

More info about it in the 16.13 announcement post.
Here’s how it happens in our case:
- Have
ParentContainerwithuseInjectReducer - Have
ChildContainerwithuseInjectReducer - When
ChildContainer’suseInjectReduceris called, the warning appears.
This happens because calling useInjectReducer calls store.replaceReducer synchronously during the render of the ChildContainer.
From what I understand, we’re not technically updating the state of a component during the render of another component but we are updating the ReactReduxContext - which contains the store and is also consumed by ParentContainer via useStore inside useInjectReducer - so that must be enough to trigger the warning.
The suggestion by the React team is to “wrap the setState call into useEffect”.
Up until September of last year, this is exactly how useInjectReducer worked: injection happened inside an effect. However, doing the injection inside an effect caused a different issue: we couldn’t guarantee that the reducer or saga was always injected before a relevant action is dispatched. (Discussed in RBP here.)
Does anyone have any thoughts or suggestions regarding how we could fix this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:54 (3 by maintainers)

Top Related StackOverflow Question
Ok after much investigation I’ve found a few scenarios where this can happen:
.mapand.filter@@redux/REPLACEaction, and re-dispatches previous actions. This is actually kind of concerning because it’s causing extra renders and could even cause different behaviour between people who have the extension and people who don’tSo we have two options:
shouldHotReloadto false in the dev tools options.shouldHotReload, however, causes another issue https://github.com/reduxjs/redux-devtools/issues/378useLayoutEffectinstead of injecting reducers synchronously on the first render.useEffects However, it will run after children’suseLayoutEffect. So if anyone is using dispatch inside auseLayoutEffect, it might not get picked upOpinion I think we should do a combination of the above:
useInjectReducer, and that pages should be able to handle that. For example, an order shouldn’t be placed twice because a component re-rendered. This is how you’re supposed to write react components anyway.useLayoutEffectinstead of injecting during the render. This is because in truth replacing reducers is a side-effect, and may cause renders in other parts of the app for any number of reasons. As one example, you don’t have to use memoized selectors, and forcing people to do so is probably not good.useInjectReducerreturn a boolean indicating if the reducer is injected. Consumers can use this value to determine whether to render children or not, which can help avoid race conditions when consumers are dispatching actions insideuseLayoutEffect. This should be rare enough that it’s not used often.useLayoutEffectrace condition in our docsshouldHotReloadto false. If set to false users will suffer https://github.com/reduxjs/redux-devtools/issues/378 but if set to true you might get different behaviour between dev and production. I’ll try to come up with an example of this.More resources: https://blog.logrocket.com/post-hooks-guide-react-call-order https://codepen.io/benlorantfy/pen/bGEJveX
Any update on this issue?