Skip to content

Commit 667d53c

Browse files
Updated README on 2022-04-19T22:13:52.899Z
1 parent 1e7509a commit 667d53c

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ 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.
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.
327327

328328
```tsx
329329
const Title: React.FunctionComponent<{ title: string }> = ({
@@ -333,9 +333,12 @@ const Title: React.FunctionComponent<{ title: string }> = ({
333333
```
334334

335335
<details>
336-
<summary><b>Using <code>React.VoidFunctionComponent</code> or <code>React.VFC</code> instead</b></summary>
336+
<summary>(Deprecated)<b>Using <code>React.VoidFunctionComponent</code> or <code>React.VFC</code> instead</b></summary>
337337

338-
As of [@types/react 16.9.48](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46643), you can also use `React.VoidFunctionComponent` or `React.VFC` type if you want to type `children` explicitly. This is an interim solution until `FunctionComponent` will accept no children by default (planned for `@types/react@^18.0.0`).
338+
In [@types/react 16.9.48](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46643), the `React.VoidFunctionComponent` or `React.VFC` type was added for typing `children` explicitly.
339+
However, please be aware that `React.VFC` and `React.VoidFunctionComponent` were deprecated in React 18 (https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59882), so this interim solution is no longer necessary or recommended in React 18+.
340+
341+
Please use regular function components or `React.VFC` instead.
339342

340343
```ts
341344
type Props = { foo: string };
@@ -399,7 +402,7 @@ const el2 = <MyArrayComponent />; // throws an error
399402
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:
400403

401404
```tsx
402-
const MyArrayComponent = () => (Array(5).fill(<div />) as any) as JSX.Element;
405+
const MyArrayComponent = () => Array(5).fill(<div />) as any as JSX.Element;
403406
```
404407

405408
[See commentary by @ferdaber here](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/issues/57).
@@ -1195,6 +1198,8 @@ This is because `ReactNode` includes `ReactFragment` which allows a `{}` type, w
11951198

11961199
[Thanks @pomle for raising this.](https://github.com/typescript-cheatsheets/react/issues/357)
11971200

1201+
With the [React 18 type updates](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210), `{}` is no longer allowed in `ReactFragment`.
1202+
11981203
</details>
11991204

12001205
<details>
@@ -1787,14 +1792,16 @@ This was done [on purpose](https://github.com/DefinitelyTyped/DefinitelyTyped/pu
17871792
```tsx
17881793
type Props = { children: React.ReactNode; type: "submit" | "button" };
17891794
export type Ref = HTMLButtonElement;
1790-
export const FancyButton = React.forwardRef((
1791-
props: Props,
1792-
ref: React.Ref<Ref> // <-- here!
1793-
) => (
1794-
<button ref={ref} className="MyClassName" type={props.type}>
1795-
{props.children}
1796-
</button>
1797-
));
1795+
export const FancyButton = React.forwardRef(
1796+
(
1797+
props: Props,
1798+
ref: React.Ref<Ref> // <-- here!
1799+
) => (
1800+
<button ref={ref} className="MyClassName" type={props.type}>
1801+
{props.children}
1802+
</button>
1803+
)
1804+
);
17981805
```
17991806

18001807
</details>
@@ -2300,7 +2307,7 @@ type pickCard = {
23002307
};
23012308
```
23022309

2303-
Note that when you implement the actual overloaded function, the implementation will need to declare the combined call signature that you'll be handling, it won't be inferred for you. You can see readily see examples of overloads in DOM APIs, e.g. `createElement`.
2310+
Note that when you implement the actual overloaded function, the implementation will need to declare the combined call signature that you'll be handling, it won't be inferred for you. You can readily see examples of overloads in DOM APIs, e.g. `createElement`.
23042311

23052312
[Read more about Overloading in the Handbook.](https://www.typescriptlang.org/docs/handbook/functions.html#overloads)
23062313

@@ -2823,6 +2830,7 @@ It is worth mentioning some resources to help you get started:
28232830
- [Palmer Group's TypeScript + React Guidelines](https://github.com/palmerhq/typescript) as well as Jared's other work like [disco.chat](https://github.com/jaredpalmer/disco.chat)
28242831
- [Sindre Sorhus' TypeScript Style Guide](https://github.com/sindresorhus/typescript-definition-style-guide)
28252832
- [TypeScript React Starter Template by Microsoft](https://github.com/Microsoft/TypeScript-React-Starter) A starter template for TypeScript and React with a detailed README describing how to use the two together. Note: this doesn't seem to be frequently updated anymore.
2833+
- [Steve Kinney's React and TypeScript course on Frontend Masters (paid)](https://frontendmasters.com/courses/react-typescript/)
28262834
- [Brian Holt's Intermediate React course on Frontend Masters (paid)](https://frontendmasters.com/courses/intermediate-react/converting-the-app-to-typescript/) - Converting App To TypeScript Section
28272835
- [Mike North's Production TypeScript course on Frontend Masters (paid)](https://frontendmasters.com/courses/production-typescript/)
28282836
- [TSX Guide](https://jenil.github.io/chota/) by [gojutin](https://github.com/gojutin/www.tsx.guide)

0 commit comments

Comments
 (0)