[英]type 'string | null' is not assignable to parameter of type 'SetStateAction<string>'.Type 'null' is not assignable to type 'SetStateAction<string>'
<Autocomplete
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
inputValue={inputValue}
onInputChange={(event, newInputValue) => {
setInputValue(newInputValue);
}}
id="controllable-states-demo"
options={options}
style={{ width: 300 }}
renderInput={(params) => <TextField {...params} label="Controllable" variant="outlined" />}
/>
Please, help me out, I am new to typescript... In the below image you will see the error.请帮帮我,我是 typescript 的新手...在下图中,您将看到错误。
Thankyou.谢谢你。
As the error says, newValue
can be either a string or null.正如错误所说, newValue
可以是字符串或 null。 It requires a string, so you should test the value of newValue
before you try to use it.它需要一个字符串,因此您应该在尝试使用它之前测试newValue
的值。
For example:例如:
if newValue !== nil {
setValue(newValue)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.