Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

useInjectReducer updates store, leading to warning "Cannot update a component (x) while rendering a different component..." #179

Description

@dungkhuc

Description

We have 2 components, one is parent and one is child. Both components have its own slice. When the child component is rendered for the first time, a warning will be thrown in the console:

image

This is caused by useInjectReducer hook. My interpretation of the issue is that the hook make change to the store, affecting both the parent and the child component.

https://github.com/react-boilerplate/redux-injectors/blob/master/src/injectReducer.js#L69
image

This is briefly mentioned at the end in #54 , after it is closed.

This issue in react-redux seems to be related reduxjs/react-redux#1640.

Steps to reproduce

  1. Create two components with separate injected reducers
  2. Nest one component in the other
  3. Start react app and navigate to route that render both component
  4. Check warning in the console.

Versions

  • react-boilerplate-cra-template: current
  • Node/NPM: 16.15.1
  • Browser: Chrome

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions