You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of [@types/react PR #46643](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46643), you can use a new `React.VoidFunctionComponent` or `React.VFC` type if you wish to declare the accepted `children` explicitly. This is an interim solution until the next major version of the type defs (where VoidFunctionComponent will be deprecated and FunctionComponent will by default accept no children).
59
+
60
+
```ts
61
+
typeProps= {
62
+
foo:string
63
+
}
64
+
// OK now, in future, error
65
+
const FunctionComponent:React.FunctionComponent<Props> = ({ foo, children }:Props) => {
66
+
return <div>{foo} {children}</div>; // OK
67
+
};
68
+
// Error now, in future, deprecated
69
+
const VoidFunctionComponent:React.VoidFunctionComponent<Props> = ({ foo, children }) => {
70
+
return <div>{foo}{children}</div>;
71
+
};
72
+
```
73
+
56
74
### Class Components
57
75
58
76
Components are type checked based on the `props` property of the component. This is modeled after how JSX is transformed i.e. the attributes become the `props` of the component.
0 commit comments