我正在尝试编写useState() hook,它可以接受数字和字符串类型作为其值。
export interface Select {
selectValue: React.Dispatch<React.SetStateAction<number | string>>;
...
}
我想要像这样使用上面的组件:
const [value, setValue] = React.useState(0);
<Select selectValue = {setValue} />
但是它给我返回了这个错误。
Type 'Dispatch<SetStateAction<number>>' is not assignable to type 'Dispatch<SetStateAction<string | number>>'.
Type 'SetStateAction<string | number>' is not assignable to type 'SetStateAction<number>'.
Type 'string' is not assignable to type 'SetStateAction<number>'.
我该如何解决这个错误?