hanki.dev

Access previous state in React setState

You can directly access previous state inside hook's setState function.

const [hook, setHook] = useState({
   name: "Gon",
   species: "Human"
});

setHook(prevState => ({
    ...prevState, name: "Killua"
}));

#react

- 4 toasts