0

I have below function

const handleClick = React.useCallback(
    (value) => {
      dispatch({ value });
    },
    [dispatch]
  );

My question is, in my case, is it necessary to have useCallback ? how React determines if the dependency is changed when the dependency is a function?

Jap Mul
  • 17,398
  • 5
  • 55
  • 66
peace and love
  • 239
  • 4
  • 13

1 Answers1

-1
  1. It is not necessary to use useCallback but using that will reflect in good performance.

  2. useCallback returns a memoized callback. According to my understanding, react invokes the function and only execute the callback function if there is any change in the dependencies that we have passed to it.

References:

  1. useCallback
Muhammad Zeeshan
  • 4,608
  • 4
  • 15
  • 41