Semantic-UI-React, selection, multi, cannot set defaultValue

I have a React component:

<Dropdown placeholder={field[propName].label} id={propName} fluid multiple selection search defaultValue={defaultOptions} options={options} /> 

So options and defaultOptions are the same arrays of the {text: 'string, value: 'string'} structure.

In the semantic source code of the UI, I found this:

 /** Initial value or value array if multiple. */ defaultValue: PropTypes.oneOfType([ PropTypes.string, PropTypes.number, PropTypes.arrayOf(PropTypes.oneOfType([ PropTypes.string, PropTypes.number, ])), ]) 

This is why my code above gives me an error:

 `Warning: Failed propType: Invalid prop `defaultValue` supplied to `Dropdown`. Check the render method of `View`.` 

So the question is, how then should I set defaultValue for the Dropdown multiple select type?

+5
source share
1 answer

defaultValue cannot be an object for semantic UI response. It can only be value. http://react.semantic-ui.com/modules/dropdown . If you look at the defaultValue details, the docs say it could be a string, number, or arrayOf.

I usually set my value in the drop-down list - using immutabilityJS - when it's on. Change.

 <Dropdown placeholder={field[propName].label} id={propName} fluid multiple selection search defaultValue={dropdownList.get('forWhat')} options={options} onChange={(e, {value}) => this.updateDropdownList('forWhat',[value:value, text:"works"])} /> 
+4
source

Source: https://habr.com/ru/post/1259418/


All Articles