I am new to the react-js
. here what I am trying to do is that,
Now what I have tried is that
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
];
handleChange = (selectedOption) => {
this.setState({ selectedOption });
console.log(`Option selected:`, selectedOption);
}
const { selectedOption } = this.state;
<div className="row" style={styles}>
<div className="col-12 d-flex">
<div className="col-md-4">
<Select
value={selectedOption}
onChange={this.handleChange}
options={options}
/>
</div>
<div className="col-md-4">
<Select
value={selectedOption}
onChange={this.handleChange}
options={options}
/>
</div>
<div className="col-md-4">
<div className="add">
<button type="button" class="btn btn-primary">Primary</button>
</div>
<div className="remove">
<button type="button" class="btn btn-success">Success</button>
</div>
</div>
</div>
</div>
So, Here when I tried to add the label then it is not coming in the one line,
can any one help me with this ?
Thanks in advance!!
the "label" will show in the first line if your "value" property is valid - make sure your selectedOption state has a valid value that exists in your options value - all according to the docs.
your code should look something like this: