State Best Practices

How to plan out a page

  1. Identify your component’s different visual states
  1. Determine what triggers those state changes
  1. Represent the state in memory using useState
  1. Remove any non-essential state variables
  1. Connect the event handlers to set the state

It can help creating a diagram like the one below, to determine what states are required.

We can then start reducing the number of states after this.

Consider that some of these may be derived from user input states, like start typing could just be the user has inputted some text, and thus input state’s length is greater than 0.

Pages