How to useState in React

A detailed look at how React.useState works


Mental Model

Component Re-render

Preserving Values between Re-renders


Lazy State Initialization

In Summary…

  • useState allows you to trigger a component re-render, add state to a function component, and preserve values between renders
  • enabling lazy state initialization is the result of passing in a function definition versus a function invocation



Software developer with a liking to avocados

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store