Last active
December 20, 2016 17:50
-
-
Save danott/fc46a381e3e36cd0b1a6049937cac8b6 to your computer and use it in GitHub Desktop.
A rough example of the idea that you can blow-away child state by passing a new key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CanResetChildren extends React.Component { | |
constructor(props) { | |
super(props) | |
this.state = this.initialState | |
window.setTimeout(this.reset.bind(this), 60000) | |
} | |
render() { | |
return ( | |
<div> | |
You have 60 seconds to complete this form | |
<SomeChildWithState | |
key={this.state.gotInitialStateAt} | |
{...someRealProps} | |
/> | |
</div> | |
) | |
} | |
reset() { | |
this.setState(this.initialState) | |
} | |
get initialState() { | |
return { | |
gotInitialStateAt: new Date().toString() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment