Answer the question
In order to leave comments, you need to log in
How to properly unmount an element (block) in react.js?
The documentation says that componentWillUnmount is fired before the element is unmounted from the DOM. But how do you unmount the element?
Simply put, I need to replace one element with another, which are tied to the same id, or simply delete the element.
How to do it competently so that componentWillUnmount would be triggered on an element that is removed from the DOM?
Answer the question
In order to leave comments, you need to log in
Don't render the component, then React will remove it from the DOM.
render() {
let component = true ? <Comp1 /> : <Comp2 />;
return (
<div>{component}</div>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question