3 ms·
You're only using it wrong if you're trying to avoid triggering hooks as something other than a performance optimization. For example, something like this shou
by TheCoelacanth 5y ago
You're only using it wrong if you're trying to avoid triggering hooks as something other than a performance optimization.
For example, something like this should work correctly even without useCallback, but you would be constantly re-subscribing for no good reason.
const callback = useCallback(...);
useEffect(() => {
const unsubscribe = subscribe(callback);
return () => unsubscribe();
}, [callback]);