Component will Unmount - React Js
App.js:
import React, { Component, useState } from 'react';
import Student from './Components/Student'
import './App.css'
class App extends Component
{
constructor()
{
super();
this.state={show:true}
}
render()
{
return(
<div>
{
this.state.show ? <Student/> :<h1>Child Component Removed</h1>
}
<h1>Component will Unmount</h1>
<button onClick={()=>this.setState({show:!this.state.show})}>Toggle</button>
</div>
)
}
}
export default App;
-----------------------------------
Student.js:
import React, {Component} from "react";
class App extends Component
{
componentWillUnmount()
{
console.warn("Componentwillunmount called")
}
render()
{
return(
<div>
<h1>Student child Component</h1>
</div>
)
}
}
export default App;
Comments
Post a Comment