Skip to main content

State in React

Reactโ€™s documentation provides some good examples of what is and isnโ€™t state:

  • Does it remain unchanged over time? If so, it isnโ€™t state.
  • Is it passed in from a parent via props? If so, it isnโ€™t state.
  • Can you compute it based on existing state or props in your component? If so, it definitely isnโ€™t state!

Whatโ€™s left is probably state.

State is different than props. Props are passed from the parent to the child to customize how the component looks or functions. State acts as the componentโ€™s memory.