The initial example given in the docs is not clear because it should be given within a ReactJS component (which I think is the main use case). This will make things easier for people getting started
var Select = require('react-select');
var options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
];
function logChange(val) {
console.log("Selected: " + val);
}
<Select
name="form-field-name"
value="one"
options={options}
onChange={logChange}
/>
I would recommend something like this
import React, { PropTypes, Component } from 'react'
import Select from 'react-select';
// styling
require('style!css!sass!react-select/dist/react-select.css');
export default class StoreBar extends Component {
constructor(props)
{
super(props)
this.state = {
value: ''
}
}
logChange(val) {
console.log("Selected: " + val);
this.setState({ value: val});
}
render(){
var options = [
{ value: 'one', label: 'One' },
{ value: 'two', label: 'Two' }
];
return(
<Select
name="form-field-name"
value={this.state.value}
options={options}
onChange={this.logChange.bind(this)}
/>
);
}
}
+1, only got my demo to work after a long search and finally stumbling upon this example. Thank you for putting this one up!
+1, this should really be the official demo, as this is what basically everyone wants to do with the thing.
Also +1 for this
Hello -
In an effort to sustain the react-select project going forward, we're closing old issues / pull requests.
We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.
If you feel this issue / pull request is still relevant and you'd like us to review it, please leave a comment and we'll do our best to get back to you.
Most helpful comment
I would recommend something like this