简体   繁体   English

Material-ui Select 组件未正确更新状态

[英]Material-ui Select component not update state correctly

I made multiple select input with Material-UI .我用Material-UI做了多个选择输入。 By default state have an array of two objects.默认状态下有一个包含两个对象的数组。 I set this state as select value, so it should show default objects as selected.我将此状态设置为选择值,因此它应该将默认对象显示为选中状态。 But problem is, that this not working, even when I try to select others items select updates this state but I can't to deselect default values.但问题是,这不起作用,即使我尝试选择其他项目选择更新此状态,但我无法取消选择默认值。 I placed my code on CodeSandbox我把我的代码放在CodeSandbox 上

The default values you created are separate than the values in vesselsList.您创建的默认值与容器列表中的值不同。 If you change your default state to this it works.如果您将默认状态更改为此,它会起作用。

 const [desiredVesselType, setDesiredVesselType] = useState([ vesselsList[3], vesselsList[4] ]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM