I defined a custom hook to do some operations and calling some APIs like below
const useCustomHook = (param1,param2) => {
const response = callAPI(param1, param2 ){ .... }
return [callAPI, response]
}
and I used this hook somewhere and it works as well : for example
const [save ,response] = useCustomHook(param1,param2);
But, I need to call save with different parameters in different condition: for example :
if (type===1)
const [save ,response] = useCustomHook(param1,'a');
else
const [save ,response] = useCustomHook(param1,'b');
type is gotten from another hook.like this
const type = useType()
However, as you know hooks can't call conditionally so the above code doesn't run.
Any ideas are appreciated.
I think you should rather use the condition inside the custom hook. You can pass the type as third argument in the custom Hook and handle the conditional logic from there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With