【发布时间】:2020-04-15 18:58:46
【问题描述】:
我正在尝试正确键入映射子组件的道具:
type Props = {
children: any
}
const MyComponent: FunctionComponent<Props> = () => (React.Children.map(children, someMapingFunction);
我一直在使用JSX.Element,但感觉不太对劲。
【问题讨论】:
-
我用
React.ReactNode -
您是否正在尝试将您的孩子键入特定的受控类型?如果没有,您可能应该使用
React.PropsWithChildren<MyProps>。这会将默认子项添加到任何道具。
标签: reactjs typescript typescript-typings children react-props