'How to use useCallback inside custom hook
got little issue here. I'm exporting a custom hook, which uses other hooks, but I get "Unhandled Rejection (Error): Invalid hook call..." Error. Looks like I'm not doing something wrong... I'm using hook inside hook, so why is this error being thrown?
const customHook = async () => {
const { values } = useValues()
const testCallback = useCallback(async () => {
const value = values
return value
}, [value])
return testCallback
}
export default customHook
Solution 1:[1]
I think the issue can be resolved by just changing the case of your component's name, try renaming it to "CustomHook". There's a rule with react hooks that you can not call use hook inside a function or component whose name is in Camel Case.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ayesha Khan |
