React 类型错误: “children” 属性类型不兼容 - 解决方法
在声明 Props 接口时,将 children 的类型指定为 React.ReactElement 而不是 React.ReactElement[]。 这是因为 children 应该是一个单独的 ReactElement 而不是一个元素数组。将 Props 接口的定义更改为以下内容应该能解决问题:
interface Props {
children: React.ReactElement;
}
然后,在函数组件的类型注解中将 Props 更改为 React.PropsWithChildren<Props>:
const ApplicationModal: React.FC<React.PropsWithChildren<Props>> = (props) => {
// ...
};
这样应该可以解决类型错误。
原文地址: https://www.cveoy.top/t/topic/p9ia 著作权归作者所有。请勿转载和采集!