Skip to content

Commit 442560b

Browse files
Updated README on 2022-04-25T07:57:42.824Z
1 parent 5728701 commit 442560b

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ Some differences from the "normal function" version:
323323

324324
- Note that there are some known issues using `defaultProps` with `React.FunctionComponent`. See [this issue for details](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/87). We maintain a separate `defaultProps` section you can also look up.
325325

326-
- It provides an implicit definition of `children` (see below) - however there are some issues with the implicit `children` type (e.g. [DefinitelyTyped#33006](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33006)), and it might be better to be explicit about components that consume `children`, anyway. With the [React 18 type updates](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210), `children` is no longer implicitly defined.
326+
- Before the [React 18 type updates](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210), `React.FunctionComponent` provided an implicit definition of `children` (see below), which was heavily debated and is one of the reasons [`React.FC` was removed from the Create React App TypeScript template](https://github.com/facebook/create-react-app/pull/8177).
327327

328328
```tsx
329+
// before React 18 types
329330
const Title: React.FunctionComponent<{ title: string }> = ({
330331
children,
331332
title,
@@ -402,7 +403,7 @@ const el2 = <MyArrayComponent />; // throws an error
402403
Unfortunately just annotating the function type will not help so if you really need to return other exotic types that React supports, you'd need to perform a type assertion:
403404

404405
```tsx
405-
const MyArrayComponent = () => (Array(5).fill(<div />) as any) as JSX.Element;
406+
const MyArrayComponent = () => Array(5).fill(<div />) as any as JSX.Element;
406407
```
407408

408409
[See commentary by @ferdaber here](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/57).
@@ -1792,14 +1793,16 @@ This was done [on purpose](https://github.com/DefinitelyTyped/DefinitelyTyped/pu
17921793
```tsx
17931794
type Props = { children: React.ReactNode; type: "submit" | "button" };
17941795
export type Ref = HTMLButtonElement;
1795-
export const FancyButton = React.forwardRef((
1796-
props: Props,
1797-
ref: React.Ref<Ref> // <-- here!
1798-
) => (
1799-
<button ref={ref} className="MyClassName" type={props.type}>
1800-
{props.children}
1801-
</button>
1802-
));
1796+
export const FancyButton = React.forwardRef(
1797+
(
1798+
props: Props,
1799+
ref: React.Ref<Ref> // <-- here!
1800+
) => (
1801+
<button ref={ref} className="MyClassName" type={props.type}>
1802+
{props.children}
1803+
</button>
1804+
)
1805+
);
18031806
```
18041807

18051808
</details>

0 commit comments

Comments
 (0)