React hooks introduces
useState
for setting component state. But how can I use hooks to replace the callback like the below code:
setState(
{ name: "Michael" },
() => console.log(this.state)
);
I want to do something after the state is updated.
I know I can use
useEffect
to do the extra things but I have to check the state previous value which requires a bit code. I am looking for a simple solution that can be used with
useState
hook.