javascript / beginner
Snippet
The useState Hook
The useState hook allows functional components to manage local state. It returns an array with two elements: the current state value and a function to update it.
snippet.js
1
2
3
import { useState } from 'react';const [count, setCount] = useState(0);
react
Breakdown
1
useState(0)
Initializes the state variable with a starting value of 0.
2
const [count, setCount]
Uses array destructuring to name the state variable 'count' and the updater function 'setCount'.