Skip to content

Instantly share code, notes, and snippets.

@danott
Last active December 20, 2016 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danott/fc46a381e3e36cd0b1a6049937cac8b6 to your computer and use it in GitHub Desktop.
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
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