317 B
317 B
Basics
const [name, setName] = useState('Edward');
const [age, setAge] = useState('0');
function handleClick() {
setName('Taylor');
setAge(a => a + 1);
}
as react batches states updates so it when it is called multiple times it may not update correctly so this updater function/functional form helps