类型 'string | null' 不可分配给类型 'SetStateAction<string>' 的参数。类型 'null' 不可分配给类型 'SetStateAction<string>'
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" />}
/>
请帮帮我,我是 typescript 的新手...在下图中你会看到错误。
谢谢。
如错误所述,newValue
可以是字符串或空值。它需要一个字符串,因此您应该在尝试使用它之前测试 newValue
的值。
例如:
if newValue !== nil {
setValue(newValue)
}
<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" />}
/>
请帮帮我,我是 typescript 的新手...在下图中你会看到错误。
谢谢。
如错误所述,newValue
可以是字符串或空值。它需要一个字符串,因此您应该在尝试使用它之前测试 newValue
的值。
例如:
if newValue !== nil {
setValue(newValue)
}