- track the previous state in react 18 friendly way. No
useEffect
required.
const [count, setCount] = React.useState(1);
const [tuple, setTuple] = React.useState([null, count]);
if (tuple[1] !== count) {
setTuple([tuple[1], count]);
}
useEffect
required.
const [count, setCount] = React.useState(1);
const [tuple, setTuple] = React.useState([null, count]);
if (tuple[1] !== count) {
setTuple([tuple[1], count]);
}