Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active April 15, 2025 18:11
Show Gist options
  • Select an option

  • Save wilmoore/10cbb60ea861bff585a0142d73bdcf9a to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/10cbb60ea861bff585a0142d73bdcf9a to your computer and use it in GitHub Desktop.
Software Engineering :: Programming :: Languages :: JavaScript :: ReactJS :: Hooks :: useState

Software Engineering :: Programming :: Languages :: JavaScript :: ReactJS :: Hooks :: useState

⪼ Made with 💜 by Polyglot.

useState

When something can be calculated from the existing props or state, don’t put it in state. Instead, calculate it during rendering. This makes your code faster (you avoid the extra “cascading” updates), simpler (you remove some code), and less error-prone (you avoid bugs caused by different state variables getting out of sync with each other). If this approach feels new to you, Thinking in React has some guidance on what should go into state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment