Estado anterior de uso
const Foo = (props) => {
const [name, updateName] = useState('Doe');
return (
<div>
<div>{name}</div>
<button
onClick={() => updateName((prevState) => (
`Old value was ${prevState}`
)
)}
>
Click me
</button>
</div>
)
}
export default Foo;
Thankful Turtle