DEV Community

Discussion on: Building Custom React Hooks

Collapse
 
mungojam profile image
Mark Adamson

thanks for the neat example. I wonder if you should be wrapping the state creation at the end in a useMemo. Otherwise components that use this hook and render for a reason unrelated to a dice roll will pick up a 'new' dice state and then end up re-rendering some other aspects unnecessarily, e.g. if there is some useMemo call in the calling component with the dice state as one of its inputs.