The Context hook is not shown unless another hook is also presen like useState or useEffect
vnvizitiu opened this issue · 7 comments
When I have a component that only uses a useContext, the hooks section is not show, but if I register a hook for state or effect, then I can inspect the context hook.
Using version a6aba5a but I noticed this for a while and I saw that there was no issue submitted at this (at least from a title point of view)
DevTools needs to re-render function components to display hooks values. In order to avoid triggering breakpoints, duplicate console logging, etc. unnecessarily- it only does this when it can tell the component uses hooks. Unfortunately useContext
isn't detectable on its own, because it doesn't write anything to the internal state field. (It's just a small wrapper around the context API.)
So the options here are either:
- Do nothing, and functions that only use
useContext
will continue to be skipped. - Always re-render every function component, even if it's unlikely to use hooks, in case it uses only
useContext
.
Neither option seems great or like the obvious right choice.
I'm fine with having it be skipped cause for debugging purposes I could run an empty effect or a bogus state.
Did not know what's involved in having that happen.
At least this is logged for future reference. The issue can be closed or kept some possible future innovation 😃
No worries. It's an interesting issue for sure.
@bvaughn useContext writes to the dependencies field so it’s detectable there.
Ah!
DevTools currently "detects" the use of hooks by looking for a non-null memoizedState
field. We could expand that check to also include non-null dependencies
field as well. That didn't occur to me. I'm not as familiar with the new context API.
Nice suggestion 😄 Thanks
v4.0.3 has just been released with this fix.
Full changelog: https://github.com/facebook/react/blob/master/packages/react-devtools/CHANGELOG.md#403-august-17-2019