Skip to content

Bug: Parent rerenders unnecessarily on Child-to-Parent setter call, while child rerenders only when changes occur. #28287

Closed
@taku-271

Description

@taku-271

React version: 18

Steps To Reproduce

  1. Define state in the parent component.
const [state, setState] = useState();
  1. Render the child component and pass the function to modify the parent component's state to the child component.
<ChildComponent setState={setState} />
  1. Calls the setter but does not change the value of state.
setState((state) => state + 0);

Link to code example: https://codesandbox.io/p/sandbox/rendering-test-vts4v2?file=%2Fsrc%2FApp.js%3A3%2C20

The current behavior

The parent component rerenders even if the state remains unchanged.
When the parent component rerenders only due to unchanged state, the child component does not rerender.
image

If the value of state has been changed, the child components are rerendered.
image

The expected behavior

The parent component should not rerender if the state remains unchanged.
If the parent component rerenders, the child component should also rerender.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions