Created
November 13, 2019 05:09
-
-
Save mrron313/ed72211d0ae053e7f34f67ae1a19a56b to your computer and use it in GitHub Desktop.
update state onchange select dropdown in react js
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
// Update state | |
constructor() { | |
super(); | |
this.state = { | |
location: 'Bangladesh' // By default it will be set to "Bangladesh" | |
} | |
this.handleLocationChange = this.handleLocationChange.bind(this); | |
} | |
handleLocationChange = (e) => { | |
this.setState({ location: e.target.value }); | |
} | |
// select drop down part in render | |
<select onChange={ (e) => this.handleLocationChange(e) } class="custom-select" id="location"> | |
<option selected value="Bangladesh">Bangladesh</option> | |
<option value="India">India</option> | |
<option value="UK">UK</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment