Duration
3 min
Access
Free
Transcript
Available

Because hooks code is regular JavaScript, extracting it to its own function is trivial and enables code sharing in a really nice way. It also allows us to encapsulate and separate concerns really cleanly. Custom hooks also compose really nicely together to build more complex hooks out of more primitive ones. Let's do this by creating a useSetState and useSafeSetState custom hook.

If you would like a more comprehensive useSetState hook, give use-legacy-state a try.