1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Create State Data that can Change in a React Component with useState

    reactReact

    Data inside of a react component that can change (with user or server interaction) is called state.

    import useState from react, and then we can use that function to create some local state by calling it with a default value:

    const [count, setCount] = useState(5)

    useState returns an array of two items: the first is the current value of the state, and the second is a function that we can use to update that state.