【发布时间】:2019-07-13 23:48:21
【问题描述】:
我正在尝试将 useState 设置器传递给子组件,但不确定如何输入。
const Parent = () => {
const [count, setCount] = useState(0);
return(
Child count={count} setCount={setCount} />
);
}
然后在Child 组件中,我尝试输入setter,但看到以下错误。
类型 'Dispatch>' 不可分配给类型 '() => void'。
我的代码是这样的
type Props = {
count: number;
// the issue is the line below
setCount: () => void;
}
const Child = ({ count, setCount }: Props) => {
.... code here
}
【问题讨论】:
标签: javascript reactjs typescript ecmascript-6 types