Member-only story

When not to use State

--

Photo by Alejandro Barba on Unsplash

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.

--

--

Vinodh Thangavel
Vinodh Thangavel

Written by Vinodh Thangavel

Passionate lifelong learner, coding enthusiast, and dedicated mentor. My journey in tech is driven by curiosity, creativity, and a love for sharing knowledge.

No responses yet