📜  移除组件 react js - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:07.289000             🧑  作者: Mango

代码示例1
class Child extends React.Component {
    constructor(){}
    dismiss() {
        this.props.unmountMe();
    } 
    render(){
        // code
    }
}

class Parent ...
    constructor(){
        super(props)
        this.state = {renderChild: true};
        this.handleChildUnmount = this.handleChildUnmount.bind(this);
    }
    handleChildUnmount(){
        this.setState({renderChild: false});
    }
    render(){
        // code
        {this.state.renderChild ?  : null}
    }

}