The "Rules of Hooks" mention:
Don’t call Hooks inside loops, conditions, or nested functions.
Does that also mean we should avoid code like this?
const useMyCoolHook = ({configKey, anotherProp}) => {
useEffect(() => {
// Do something with configKey here
}, [configKey])
useEffect(() => {
// Do something with configKey and anotherProp here
}, [configKey, anotherProp])
}
const Component = ({configKey, anotherProp}) => {
if(configKey === undefined) { return null; }
useMyCoolHook({configKey, anotherProp})
return (
<h1>Hello world</h1>
)
}
If so, is there a way to avoid having to include the condition inside each of the useEffect hooks?