rules of hooks question
Im looking at an article rn (https://kentcdodds.com/blog/how-to-use-react-context-effectively) and trying to do something similar in my context with using a custom hook that calls the useContext(). However im getting invalid hook call error, im assuming for abusing the rules of hooks.
10 Replies
that is what my hook looks like
pic of error
here a snippet from the article
looking at
useCount()
in particular
is it because im passing in args to the function?
im planning on doing something else with the string passed in before the ctx.setSearchQuery
is called within my hook is the reason im using a hook.useCount here is a function and not a component, Hooks can only be called inside a component that too top level, it cant even be called inside useEffect, functions etc
So you need to put your React.useContext inside a component and call it from there
If you are making a custom hook, naming is super important. It needs to have the prefix 'use' as in 'useBlahBlah' tell react this is a hook, treat it as such".
yea i took off use because too check if it still error'ed out or if it was just the ts rule
afaik react doesnt actually care if you use
use
right? its just for linitingAh you are quite right I thought it was implicit behavior, How have you set up the context?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View