Member-only story
When not to use State
Jun 25, 2023
In React, this component-specific memory is called state.
Components often need to change what’s on the screen as a result of an interaction. Typing into the form should update the input field, clicking “next” on an image carousel should change which image is displayed, clicking “buy” should put a product in the shopping cart. Components need to “remember” things: the current input value, the current image, the shopping cart.
The above statement is from react offical documentation
What should not be a state
- When the value
does not changes over the time and remains static
. - When the value can be
computed with other state / props or static variables
.