React: Each render has its own state, props, event handlers, and effects
23 October 2022 (Updated 23 October 2022)
Each render has its own state and props
Consider the following snippet:
When this component is re-rendered because of the setCount(count + 1
) call, something like the following happens:
Each time setCount
is called, the Counter
component is rendered with a different count
value. Each render “sees” its own count value that’s isolated between renders.
Each render has its own event handlers
Just as each render has its own state and props, it also has its own event handler. So in the following snippet, each render will have its own version of handleAlertClick
in the following snippet:
The above translates to something like:
Each render has its own effects
Sources
Tagged:
React
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment