score:3

Accepted answer

You don't need to memoize the returned object unless you are passing the Object directly to function of useEffect in which case reference will fail

You don't need to add an extra layer of memoization over useCallback if you use it like this:

const Comp = () => {
   const { toggleOn, toggleOff } = useToggle();

   useEffect(() => {
      console.log('Something here')
   }, [toggleOn]);  
   return (
       <Child toggleOn={toggleOn} toggleOff={toggleOff} />
   )
}

However the usages like below code will need memoization of the returned object

const Comp = () => {
   const toggle = useToggle();

   useEffect(() => {
      console.log('Something here')
   }, [toggle]);  
   return (
       <Child toggleHandlers={toggle} />
   )
}

Related Query

More Query from same tag