Skip to content

Instantly share code, notes, and snippets.

@suneg
Created February 20, 2019 12:11
Show Gist options
  • Save suneg/c7eda618cbd8c7831711c1ec4cbc0232 to your computer and use it in GitHub Desktop.
Save suneg/c7eda618cbd8c7831711c1ec4cbc0232 to your computer and use it in GitHub Desktop.
Clear React component state
// How to clear the state of the current component
// (set all state properties to undefined)
let clearerObject = Object.keys(this.state).reduce((prev, k) => {
prev[k] = undefined;
return prev
}, {});
this.setState({
...clearerObject
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment