每当我点击根节点中的按钮时,我都会有一个呈现警报组件的功能, 并且行为是当我解除警报时它应该返回null,从而将它删除到我检查过的mountNode,它确实如此。但是,当我再次单击该按钮时,它似乎没有渲染,实例化。怎么样?
function buttonHandler(event) {
event.preventDefault();
ReactDOM.render(
<CustomAlert/>,
document.getElementById(mountNode)
);
}
组件:
import React from 'react';
import {Alert} from 'react-bootstrap';
export default class CustomAlert extends React.Component {
constructor(props) {
super(props);
this.state = {
show: true
}
this.handleAlertDismiss = this.handleAlertDismiss.bind(this);
}
handleAlertDismiss() {
this.setState({ show: false });
}
render() {
if(this.state.show) {
return (
<Alert bsStyle="danger" onDismiss={this.handleAlertDismiss}>
<h4> Test </h4>
</Alert>
);
} else {
return null;
}
}
}