Our website is styled with Bootstrap. I'm trying to implement a React-Bootstrap select component. How do I make it into a controlled component? More specificly, how do I mark the selected option. Usually it is with a value property in the parent component. Is this how it works for React-Bootstrap select as well? What function runs when a new option is selected? What are the parameters of the function?
1 Answer
After trial and error here is an example:
const applySelect = (event) => {someFunction(event.target.value)};
const selectedValue = 3;
return (
<FormGroup controlId="formControlsSelect">
<ControlLabel >Label String</ControlLabel>
<FormControl componentClass="select" placeholder="select" value={selectedValue} onChange={applySelect}>
<option value="0" key="0">Option 0</option>
<option value="1" key="1">Option 1</option>
<option value="2" key="2">Option 2</option>
</FormControl>
</FormGroup>