javascript - React Select - setState of prop -
i trying set state of brandselect prop in reactjs using react select confused how can done?
here current code:
class vehicleselect extends react.component { constructor(props) { super(props); this.state = { brandselect: ""}; } render() { var options = [ { value: 'volkswagen', label: 'volkswagen' }, { value: 'seat', label: 'seat' } ]; return ( <select name="form-field-name" value={this.state.brandselect} options={options} placeholder="select brand" searchable={false} onchange={} /> ) } };
when option selected want state set option chosen.
does know how done react select documentation doesn't cover this? far have tried making function set state attached onchange prop didn't work.
you can try add _onchange
handler component, handle changes form <select />
component.
class vehicleselect extends react.component { constructor(props) { super(props); this.state = { brandselect: ""}; } _onchange(value) { //console.log(value) - see recive <select /> this.setstate({brandselect: value}); } render() { var options = [ { value: 'volkswagen', label: 'volkswagen' }, { value: 'seat', label: 'seat' } ]; return ( <select name="form-field-name" value={this.state.brandselect} options={options} placeholder="select brand" searchable={false} onchange={this._onchange.bind(this)} /> ) } };
Comments
Post a Comment