我正在尝试将一个prop传递给功能组件(使用打字稿),但出现渲染错误,但不知道为什么。
这是导入组件的文件:
<ActiveCheckbox active={true} />
这是组件文件:
import React from "react";
import { Checkbox } from "@chakra-ui/core";
export const ActiveCheckbox: React.FC = (active: boolean) => {
return <Checkbox variantColor="teal" mr={2} isChecked={active}></Checkbox>;
};
错误:
TypeScript error in /src/components/active-checkbox.tsx(4,14):
Type '(active: boolean) => JSX.Element' is not assignable to type 'FC<{}>'.
Types of parameters 'active' and 'props' are incompatible.
Type '{ children?: ReactNode; }' is not assignable to type 'boolean'. TS2322
有人可以在这里解释我在做什么错吗?我也尝试过在<any>
之后附加React.FC
,但无济于事。
谢谢您的建议