Forcing A Child Remount With The Key Prop
class MyComponent extends React.Component {
state = {
remountKey: (new Date()).getTime(),
}
resetCounter = () => {
this.setState({
remountKey: (new Date()).getTime(),
});
}
render() {
return (
<div>
{/* some other stuff in my component */}
<Counter key={this.state.remountKey} />
<button onClick={this.resetCounter}>Reset Counter</button>
</div>
);
}
}Last updated