I think you need something like this:
class t extends React.Component {
state = {
forceRerender: 0,
};
testDoneHandler(e) {
if (this.state && e.origin === document.location.origin) {
if (e.data === "testingClosed") {
this.setState((value) => ({ forceRerender: value.forceRerender + 1 }));
}
}
}
componentDidMount() {
window.addEventListener("message", this.testingClosed.bind(this));
}
console.log('forceUpdate', this.state.forceRerender);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…