{myheader}
); }}class Child extends React.Component{componentWillUnmount(){alert("The header component is about to be unmounted."); }render(){return(React Ref Componentwillunmount
# React componentWillUnmount() Method
[ React Component Lifecycle](#)
The componentWillUnmount() method format is as follows:
componentWillUnmount()
The componentWillUnmount() method is called directly before the component is unmounted and destroyed.
The setState() method should not be called in componentWillUnmount() because the component will never be re-rendered. After a component instance is unmounted, it will never be mounted again.
In the following example, the componentWillUnmount() method will be called when the component is about to be removed from the DOM:
## Example
class Container extends React.Component{constructor(props){super(props); this.state = {show: true}; }delHeader = () =>{this.setState({show: false}); }render(){let myheader; if(this.state.show){myheader = ; }; return(
YouTip