useState is a React hook that allows you to add state to function components.
It returns an array with the current state value and a function to update it.
useState is the most basic hook and is used for managing local component state.
It can be called multiple times in a single component for different state variables.
import React, { useState } from 'react';
function Example() { const [count, setCount] = useState(0); const [name, setName] = useState('');
return ( <div> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}> Increment </button> <input value={name} onChange={(e) => setName(e.target.value)} /> </div> ); }