New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hook values don't show in react-devtools #7
Comments
@Venryx Meanwhile can you test new version 0.4.0 as you have many real app use case? thank you! |
hum seems that react dev tools does not inject hookLog if componet is a Class one. i see only 2 possible solutions
maybe the best solutionsi 1? without modding react dev tools? what do you think about? |
I think the first approach is probably better, since it doesn't require your having to maintain a fork of react-dev-tools, and it works without the developer having to install a new browser extension. I think it'll work. It's a bit less "elegant", but practically speaking the end result should work as well as the regular hook inspection UI. The only difficulty points:
|
yes i will put a @hookData into this.state the only problem is if someone use a key like "@hookData" 🎉 but reactDevTools does not support keySymbol so there is no other way! to be clear that "@hookData" is a reseved key on this.state, i think to export a function to activate debugMode on indexApp.js import { supportReactDevTools } from 'react-universal-hooks';
supportReactDevTools ({ active: process.env!=="production", stateKey:'@whatYouWant' });
//default active:false, stateKey:'@hookData' |
@Venryx import { supportReactDevTools } from 'react-universal-hooks';
supportReactDevTools ({ active: process.env!=="production" }); |
Nice! Now react-universal-hooks has feature parity with the official hooks. (at least as far as I have used them) |
The values for the
useState
hooks don't show in react-devtools (unlike standard hooks).Possible explanations
react-universal-hooks
differs from the official hooks, so react-devtools can't recognize them.Potential solutions
Workaround
In the meantime, I've come up with a workaround for accessing the hook data, by wrapping the hooks and having them store their data (using object-mutation to prevent re-renders) on something like
component.state.hookValues
.The component is accessible from the hooks because I have a
currentCompBeingRendered = this
line run at the start of each render function. (I already auto-wrap therender
function of components, so I was able to just add to that)Here are the areas of code accomplishing my workaround: (in this case, the type of hook exposed is a variant of
useSelector
from react-redux, but you could use the same approach for any hook type)render
funcs, to track the currently-rendering compcomp.state.@debug
(comp.Debug(...)
just adds tocomp.state.@debug
)The text was updated successfully, but these errors were encountered: