Bug: Functional component rerender when same state
See original GitHub issueReact version: 16.13.1
Steps To Reproduce
The current behavior
- first render -> ‘render’ log
- textA default value is ‘A’
- changeA Click and textA changed ‘AA’ ->
render
log - changeA Click, before textA value is ‘AA’ after textA value is ‘AA’. ->
render
- And then changeA Click, nothing ‘render’ log
- changeTextB Button Click and textB is always render. ->
render
- changeTextA Button Click
render
log after changeTextB clicked
The expected behavior
Expected behavior is do not render in Step4 and Step7. Because, before textA state is ‘AA’ and after textA state is ‘AA’. -> nothing change
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
react functional component re-render one time even the state's ...
1 Answer 1 · render useAutoIncrement. this is the first console message your component runs into when the function fires · CustomHook render....
Read more >How and when to force a React component to re-render
Generally, forcing a React component re-render isn't best ... to see if both the preview and new value for state reference the same...
Read more >Bug: setState does not rerender a functional component when ...
If I change the property of the same object, say changing the age field to 23 the rerender triggers fine. And why should...
Read more >5 Ways to Avoid React Component Re-Renderings
useState() Hook is widely used in React applications to re-render the components on state changes. However, there are scenarios where we need to...
Read more >When does React re-render components? - Felix Gerschau
As we already saw before, React re-renders a component when you call the setState function to change the state (or the provided function...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@heecheolman once again, quote from the same page
Which means that when you call
setState
with the same value it is not guaranteed that the function is not going to be called again, but even if it is, it is not an actual rerender, since child components are not going to be rerendered.example: codesandbox
Set 1
Button: “render” print, Because state changes0
to1
Set 1
Button: “render” printIn React document
Object.is(1, 1)
returnstrue
. But why React will render in Step3 ?Similar stackoverflow question link