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.

Revisions

  1. suneg created this gist Feb 20, 2019.
    11 changes: 11 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // 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
    });