forgo.unmount() not called after removing element
See original GitHub issueThe unmount()
function does not call when unmounting a component. Sandbox
import * as forgo from "forgo";
const App = () => {
const component = new forgo.Component({
render() {
return <p>Tooltip</p>;
}
});
component.unmount(() => alert("unmounted!"));
return component;
};
forgo.mount(<App />, document.getElementById("root"));
// forgo.mount(null, document.getElementById("root"));
document.body.removeChild(document.getElementById("root"));
I’m not entirely sure if either method correctly unmount a Forgo component.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Delete an Item from Array not Rendering ReactJS Hooks
You are rendering data from props.listofapi but updating array, your changes don't get updated because you are changing the wrong array.
Read more >Toggle called from unmounted Tooltips · Issue #1255 - GitHub
Error message is being printed in the console because setState is being called on an unmounted component (UncontrolledTooltip). What should be ...
Read more >React - How to Check if a Component is Mounted or Unmounted
This is a quick post to show how to track the mounted status of a React component so you can check if it's...
Read more >Remove element from DOM in React way - DEV Community
We will be using useEffect Hook to execute JavaScript Window.setTimeout() function which will help hide an element in the DOM (a side effect)....
Read more >Understanding common frustrations with React Hooks
React Hooks can be frustrating despite their popularity and widespread use. Learn about some of the drawbacks to using React Hooks.
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 FreeTop 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
Top GitHub Comments
Thank you for the quick response, I managed to adapt your example into a small helper. It works great 😄
Right now it’s presumed that unmounts happen when a Forgo render detects that a previously-displayed component stops being displayed. That works fine inside the Forgo app, but isn’t helpful if something outside Forgo needs to trigger an unmount of the whole app.
Forgo doesn’t have a solution in place for that yet because you’re the first person we’ve heard from who has integrated Forgo with other apps (vs greenfield work done entirely in Forgo).
For the moment, a hacky workaround would look like this:
Basically you put all the app logic that needs to care about the unmount lifecycle inside a component that you can rerender to unmount all of its decendants.
That’s really ugly, but it’ll at least get you moving today.
I’m looking into how practical it would be to expose a
forgo.unmount(el)
function for external logic to call, that would do all the teardown and remove the descendants ofel
. If that’s straightforward, I can get that implemented and published promptly.Longer term, we’ll need to integrate with
MutationObserver
to allow arbitrary DOM operations on anything Forgo renders. But that’ll be a lot more complicated to implement safely, so I don’t expect to push that out soon.