Created
November 26, 2019 04:57
-
-
Save jccdev45/09ee40d01a2503e0148cdc2ec9f553b9 to your computer and use it in GitHub Desktop.
Update Avatar
This file contains hidden or 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
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