troch / reinspect

Use redux devtools to inspect useState and useReducer :mag_right:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do not call React hooks inside other hooks or conditions

iagobruno opened this issue · comments

My app is complaining in the console about a hooks error:

image

But I went to investigate and my components are following the rules for hooks described in the React documentation. I looked deeper and I discovered that the errors are in your package, specifically in these lines:

const [store, reducerId] = useMemo<[EnhancedStore, string | number]>(
() => [useContext(StateInspectorContext), id],
[]
)

const [store, reducerId] = useMemo<[EnhancedStore, string | number]>(
() => [useContext(StateInspectorContext), id],
[]
)

if (!store || !reducerId) {
return useReactState<S>(initialState)
}

return store || !reducerId
? useHookedReducer(reducer, initialState, store, reducerId)
: useReactReducer<S, A>(reducer, initialState)

I tried to fix it for you but you're going to have to rewrite a part of the code.

Hello, should be fixed now with v1.0.0 (warning appeared in v16.8.0 of React).