useState looks simple on the surface, but behind it is one of the core ideas that makes React work: persistent state + re-rendering. In this article, we'll build a tiny version of useState ourselves to understand the mental model behind it.

Understanding the Basic Idea Behind useState

First, we know that the useState returns a state and a function to update that state.

const [state, setState] = useState()

Enter fullscreen mode