Course lesson
Create State Data that can Change in a React Component with useState
Data inside of a react component that can change (with user or server interaction) is called state.
- Duration
- 1 min
- Access
- Pro
- Transcript
- Available
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.