Component gets unmounted = ref is null while I interact with a component
See original GitHub issueHello Michele!
I was playing with this example in Styleguidist cookbook: how-to-use-refs-in-examples
Took me quite a while to understand why the example would not work on my almost clean version of styleguidist + snapguidist.
When I click the button in the even more simplified example below I get an error because snapguidist basically unmount the component so ref gets called with null (is that correct?)https://github.com/facebook/react/issues/9328#issuecomment-298438237
Could this lead to issues? I’m interacting with a component that is unmounted?
Example to try on a clean installation of styleguidist+snapguidist
let myEl;
<div>
<button onClick={() => myEl.value = 'Pizza'}>Insert</button>
<input ref={ref => myEl = ref} />
</div>
Issue Analytics
- State:
- Created 6 years ago
- Comments:10
Top Results From Across the Web
React: ref to child component is null after remounting by ...
I know that refs are set to null when a component unmounts, but by rendering a new version of Game , I would...
Read more >Refs and the DOM
React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts. Refs...
Read more >Avoiding useEffect with callback refs - TkDodo's blog
Interacting with DOM nodes doesn't necessarily need useEffect. ... It will be set back to null when the component is unmounted.
Read more >React: Prevent state updates on unmounted components
In the above case, React tries to set the state of an unmounted component, which is not necessary since the component is not...
Read more >Refs to Components | React
Note that when the referenced component is unmounted and whenever the ref changes, the old ref will be called with null as an...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This package has been updated to the latest version of Styleguidist (6.2.2) and React (16.2.0). The issue is not solved yet (unfortunately), but there’s a workaround:
Hello @goransm, this seems a different problem. Would you mind opening a new issue and provide a non-working example? Thank you very much!