Closed
Description
React version: 18
Steps To Reproduce
- Define state in the parent component.
const [state, setState] = useState();
- Render the child component and pass the function to modify the parent component's state to the child component.
<ChildComponent setState={setState} />
- 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.
If the value of state has been changed, the child components are rerendered.
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.