React DevTools Hooks not editable - reactjs

I'm using React 16.8.x and the latest version of the React DevTools. In some cases, I'm able to inspect and modify hooks like useState no problem. But in other cases, the hooks appear to be read only - I can't modify them from the dev tools. Clicking on them, there is no way to make any changes to their values.
Is there any rhyme or reason for why I can edit hooks from the dev tools sometimes but not others?

Related

Is REACT State in Production visible in DevTools or something?

Can you See State variables in Production or are they private in the class and not viewable from outside?
According to the answer of this question: Disable chrome react DevTools for production you are able to disable the use of the react dev tools on your production site, however this would not absolutely stop the user from reading the state as they could always find & disable that line of code, or find some other way of accessing the state.
React runs entirely inside the user's browser, and because of this it is not possible to completely prevent the user from accessing the source code, or things like the state.
To view state, you will need to install React's Devtool
Then open your developer tool then switch to the component tab:
Find and click to your component that has a state, then you will see your state also your props on the right side:
You can use react devtools to inspect state and props of a component.
Yes, you can check them via something like React dev tools.

How to view and update the hooks state value in React devtool?

I am using react hooks, but I find I couldn't expand/view/edit the hooks state value in chrome react dev tools.
Is this a known limitation of react devtools?
last time I checked this was a work in progress and is on the roadmap, you just have to wait for its release or you can subscribe to pre-releases:
https://react-devtools-experimental-chrome.now.sh/

What are the capabilities of React Hot Loader + hot-loader/react-dom as it relates to React Hooks?

I just updated my react configuration to use the new API for React Hot Loader. The top-level documentation for React Hot Loader (see: github page) has me a little confused as to what my expectations should be for this new setup.
There's a section very close to the top entitled Hook support, and it gets into what the React Hooks support looks like. However, I'm not really following the language used there. For example, does
❄️ useState(initialState); // will never updated (preserve state)
imply that any state tracked with useState will never be preserved across hot reloads?
In my ideal world, everything handled by Hooks could be tracked across reloads... but I have no idea if that is possible.
Can somebody explain the expected behaviour for React Hooks as they relate to hot reloading (specifically when using these libraries in a way that enables storing the state of React Hooks across reloads)? I recognize that the language currently used in the docs might be clear to some, but it is not to me. :(

React-devtools for hooks?

I use the react-devtools Chrome extension. When I set state using hooks (useState) to set an object in state, the actual setting of state seems to work fine. In devtools however, that state object shows that the Hooks > State has content ({...}), it also implies that the content is accessible . When I click on the “expand” (down arrow icon) nothing happens; I cannot view the object’s entries. Am I missing something or do devtools not work with hooks?
Tl:dr How do i use react-devtools to view Hooks state?
I see the same thing, though the issue is only with objects. Primitive values in state seem to show up fine.
It was logged as an issue 3 weeks ago: https://github.com/facebook/react-devtools/issues/1282
I'm surprised it hasn't already been addressed, but I suspect it will be addressed soon now that hooks are released.
I have also seen on Twitter that Brian Vaughn has been working on a rewrite of React devtools:
https://twitter.com/brian_d_vaughn/status/1093962235116810240
https://github.com/bvaughn/react-devtools-experimental
but it sounds like it will be a little while yet before that is ready for broad use.
Update with React v16.8
React Hooks are now supported by React DevTools.
Source: https://reactjs.org/blog/2019/02/06/react-v16.8.0.html

What changes to a component state can I make using React devtools?

I've got a component which consists of an object, which contains an array of objects, which in turn has keys and strings
this.state = {
dinosaurs: [
{ era: "jurassic", name: "diplodocus", diet: "herbivore" },
{ era: "cretaceous", name: "velociraptor", diet: "carnivore" },
]
}
When I open up the component in react devtools, I find I can edit the strings such as "jurassic" or "diplodocus" by double clicking on those strings, but I apparently can't make changes to the keys such as "era", or the array of dinosaurs. However, it could be possible to change it with React DevTools but I'm doing it incorrectly.
I'm using React DevTools within Google DevTools.
What can and can't I change in a component's state using React DevTools?
I tried looking at the GitHub readme, and I can see a mention of editing state in the section side pane, but no mention of what can and can't be edited.
I looked at How to set React component state and props from browser but there was a comment telling the user to read the friendly manual for React DevTools, plus answers that didn't address what is or isn't possible using React DevTools.
It appears that React DevTools locks out functionality based on whether the page you're looking at is using the "development build of React" or the "production build of React".
I'm currently trying to debug something between my local (development) version of an app and the deployed (production) version of the same app. To test something in the deployed (production) version, it would be helpful if I could open React DevTools, click into the component, and edit a prop. Alas, as far as I can tell, there is absolutely no way to edit one of the props in that production build version of the website via React DevTools.
Contrast that with my local (development) version. I can click into any component in React DevTools, then edit any props (or state) I want and the component immediately renders with the new prop value. That appears pretty easy and straightforward: just double-click what you want to edit and type away.
TL;DR: Certain prop/state editing features of React DevTools appear to be locked down depending on the React build version. If you're not sure which version you're looking at, see the link above. If you need to edit props on something that's a deployed, production build of React, you (probably*) can't. Aggravating, but I feel your pain.
[*Probably because A) I might be wrong (that would be great, someone please comment how to do it), it's not very clear in the first place about when it's editable vs not editable; B) If you could somehow trick the React DevTools into treating the page like it's a development build, it might be possible (or it might break hideously), but checking that requires more effort than I can spare.]
Some editorializing:
I would love for the above to not be true, and it's especially aggravating because I don't see a reason why it's necessary. Perhaps I don't understand enough about the difference between the dev and prod versions, but you can still view props/state on a production version using the React DevTools: it doesn't seem like a big leap to be able to also edit it considering that the functionality is all there when it's a development version. But once again, maybe I don't see the reasons behind this.

Resources