Created
February 7, 2020 13:22
-
-
Save erikdubbelboer/d62060aaccf33ad61ff8d499ef8358e1 to your computer and use it in GitHub Desktop.
This file contains 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 App extends React.Component { | |
state = { | |
value: localStorage.getItem('info') || '' | |
}; | |
componentDidUpdate() { | |
localStorage.setItem('info', this.state.value); | |
} | |
onChange = event => { | |
this.setState({ value: event.target.value }); | |
}; | |
render() { | |
const { value } = this.state; | |
return ( | |
<div> | |
<input value={value} type="text" onChange={this.onChange} /> | |
<p>{value}</p> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment