Search code examples
reactjsreact-bootstrap

react bootstrap multiselect default value


I am using react-bootstrap-multiselect for my project. I need to pass a default value to it before loading. Does react-bootstrap-multiselect have an API to pass a default selected value(s)?

<Multiselect
       onChange={this.handleMultiSelect}
       value={this.props.multiSelectData}
       data={this.props.multiSelectData}
       buttonWidth="10
       multiple
    />

I want to pass a dynamic value, which will depend on a user click.

Thanks


Solution

  • For everyone who comes across this question again:

    <Form.Control as="select" multiple defaultValue={['FOO', 'BAR']}>
        <option>FOO</option>
        <option>NOT SELECTED</option>
        <option>BAR</option>
    </Form.Control>
    

    You can simply set an array as defaultValue.

    In the example above FOO and BAR are selected.