[英]React: Binding element 'children' implicitly has an 'any' type
I have this simple code and I want to use "children" but when I use it I get this error:我有这个简单的代码,我想使用“儿童”,但是当我使用它时,我得到了这个错误:
Binding element 'children' implicitly has an 'any' type.
How can I solve this problem?我怎么解决这个问题?
const ResponsiveContainerGrid = ({ children }) => {
const classes = useStyles();
return (
<div>
<Grid
className={classes.root}
container
direction="row"
justifyContent="center"
alignItems="center"
>
{children}
</Grid>
</div>
);
};
export default ResponsiveContainerGrid;
You can type your component like this:您可以像这样键入组件:
import { FC } from "react";
const ResponsiveContainerGrid: FC = ({ children }) => { ... }
This way, the children prop will be typed implicitly.这样,children 属性将被隐式输入。
FC
stands for Functional Component, and has already a predefined children
props. FC
代表Functional Component,并且已经预定义了children
props。 If you want to use a custom prop, then you can type it like this:如果你想使用自定义道具,那么你可以这样输入:
const ResponsiveContainerGrid: FC<{myprop: MyPropType}> = ({ children, myProp }) => { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.