Skip to content

Commit fa29113

Browse files
committed
Add Void Function Components
1 parent 96f49e9 commit fa29113

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/jsx/react.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ const MyComponent: React.FunctionComponent<Props> = (props) => {
5353
<MyComponent foo="bar" />
5454
```
5555

56+
### Void Function Components
57+
58+
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+
type Props = {
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+
5674
### Class Components
5775

5876
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

Comments
 (0)