While not strictly necessary, not doing so creates a new callback function every single timeuseToggle is evaluated (as does defining a callback in the onClick={() => ...} props), which means every time a component receives the new callback function, it re-renders, even though nothing about the callback actually changed.
Consider using
useCallback
While not strictly necessary, not doing so creates a new callback function every single time
useToggle
is evaluated (as does defining a callback in theonClick={() => ...}
props), which means every time a component receives the new callback function, it re-renders, even though nothing about the callback actually changed.Great. Thanks for the suggestion and the efforts to update the example :) :)