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

InstructorChris Achard

Share this video with your friends

Send Tweet

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.