我使用https://github.com/JedWatson/react-select。
我的组件示例:
selectedOptions : [] 在第一个加载组件中,多选为空。当我选择一些值时,我将值写入selectedOptions。在这种情况下,它可以正常工作。但是当我清除selectedOptions视图时不会更新。
有示例 https://codesandbox.io/s/xovn7n2lz4
<Select
defaultValue={selectedOptions}
isMulti={isMulti}
onChange={onChange}
options={options}
placeholder={placeholder}
styles={colourStyles}
theme={(theme) => ({
...theme,
position: 'static',
borderRadius: 0,
colors: {
...theme.colors,
primary25: darkTheme.colors.hoverColor,
primary: darkTheme.colors.hoverColor,
neutral0: normalElemColor,
neutral80: standardFontColor,
},
spacing: {
...theme.spacing,
controlHeight: 24,
baseUnit: 1
}
})}
/>
Run Code Online (Sandbox Code Playgroud)