Skip to content

Instantly share code, notes, and snippets.

@jccdev45
Created November 26, 2019 04:57
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 jccdev45/09ee40d01a2503e0148cdc2ec9f553b9 to your computer and use it in GitHub Desktop.
Save jccdev45/09ee40d01a2503e0148cdc2ec9f553b9 to your computer and use it in GitHub Desktop.
Update Avatar
updateAvatar(e) {
// Grab the name + value from the select
const target = e.target;
const { name, value } = target;
// Spread + destructure the options from state
const { options } = { ...this.state };
// Update the matching option with
// the value of the select and set state
const currentState = options;
currentState[name] = value;
this.setState({
options: currentState,
// Use .replace() to look for the matching
// option and replace with the new value
avatar: this.state.avatar.replace([name], `${[name]}=${value}&`)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment