DEV Community

Discussion on: A Really Simple Intro to localStorage in React

Collapse
nithish_13 profile image
Nithish Kumar

Instead of handling changes for name and username seperately, you can simply do like this,
handleChange = evt => {
this.setState({ [evt.target.name] : evt.target.value })
} and add name attribute of value matching the value of this.state.name || .username. in the respective input fields.

So that the code looks cleaner. Also, the values from the localstorage, always remains the first set of values provided by the user. It would be nice to store recent set of values to the localstorage.
Btw, thanks for the post. 🙌🙌