In React, useState is a built-in hook that allows you to add state to a functional component. State is a way to store and manage data within a component. The useState hook takes an initial state value and returns an array with two elements:
The first element is the current state value.
The second element is a function that can be used to update the state.
`mport React, { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
function handleIncrement() {
setCount(count + 1);
}
In React, useState is a built-in hook that allows you to add state to a functional component. State is a way to store and manage data within a component. The useState hook takes an initial state value and returns an array with two elements:
`mport React, { useState } from 'react';
function Counter() { const [count, setCount] = useState(0);
function handleIncrement() { setCount(count + 1); }
return (
Count: {count}
); }`