how to optimize custom hook in react by using usecallback