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
Copy file name to clipboardExpand all lines: README.md
+15-44Lines changed: 15 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -219,9 +219,7 @@ Local dev setups:
219
219
-[TSDX](https://tsdx.io/): `npx tsdx create mylib` for Creating React+TS _libraries_. (in future: [TurboRepo](https://twitter.com/jaredpalmer/status/1346217789942591488))
220
220
221
221
<details>
222
-
<summary>
223
-
Other tools
224
-
</summary>
222
+
<summary><b>Other tools</b></summary>
225
223
226
224
Less mature tools still worth checking out:
227
225
@@ -255,7 +253,7 @@ import ReactDOM from "react-dom";
255
253
256
254
<details>
257
255
258
-
<summary>Explanation</summary>
256
+
<summary><b>Explanation</b></summary>
259
257
260
258
Why `allowSyntheticDefaultImports` over `esModuleInterop`? [Daniel Rosenwasser](https://twitter.com/drosenwasser/status/1003097042653073408) has said that it's better for webpack/parcel. For more discussion check out <https://github.com/wmonk/create-react-app-typescript/issues/214>
<summary><b>Why is `React.FC` discouraged? What about `React.FunctionComponent`/`React.VoidFunctionComponent`?</b></summary>
306
+
<summary><b>Why is <code>React.FC</code> discouraged? What about <code>React.FunctionComponent</code>/<code>React.VoidFunctionComponent</code>?</b></summary>
309
307
310
308
You may see this in many React+TypeScript codebases:
<summary>Using `React.VoidFunctionComponent` or `React.VFC` instead</summary>
336
+
<summary><b>Using <code>React.VoidFunctionComponent</code> or <code>React.VFC</code> instead</b></summary>
339
337
340
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`).
341
339
@@ -490,7 +488,7 @@ function Counter() {
490
488
491
489
<details>
492
490
493
-
<summary><b>Usage with `Reducer` from `redux`</b></summary>
491
+
<summary><b>Usage with <code>Reducer</code> from <code>redux</code></b></summary>
494
492
495
493
In case you use the [redux](https://github.com/reduxjs/redux) library to write reducer function, It provides a convenient helper of the format `Reducer<State, Action>` which takes care of the return type for you.
496
494
@@ -526,9 +524,7 @@ function DelayedEffect(props: { timerMs: number }) {
526
524
```
527
525
528
526
<details>
529
-
<summary>
530
-
Solution to the above example
531
-
</summary>
527
+
<summary><b>Solution to the above example</b></summary>
532
528
533
529
```tsx
534
530
function DelayedEffect(props: { timerMs:number }) {
Note that you are opting out of type safety here - you will have a runtime error if you forget to assign the ref to an element in the render, or if the ref-ed element is conditionally rendered.
587
583
588
584
<details>
589
-
<summary>
590
-
591
-
Tip: Choosing which `HTMLElement` to use
592
-
593
-
</summary>
594
-
585
+
<summary><b>Tip: Choosing which <code>HTMLElement</code> to use</b></summary>
595
586
596
587
Refs demand specificity - it is not enough to just specify any old `HTMLElement`. If you don't know the name of the element type you need, you can check [lib.dom.ts](https://github.com/microsoft/TypeScript/blob/v3.9.5/lib/lib.dom.d.ts#L19224-L19343) or make an intentional type error and let the language service tell you:
597
588
@@ -975,11 +966,7 @@ let el = <Greet age={3} />;
975
966
```
976
967
977
968
<details>
978
-
<summary>
979
-
980
-
`JSX.LibraryManagedAttributes` nuance for library authors
981
-
982
-
</summary>
969
+
<summary><b><code>JSX.LibraryManagedAttributes</code> nuance for library authors</b></summary>
983
970
984
971
The above implementations work fine for App creators, but sometimes you want to be able to export `GreetProps` so that others can consume it. The problem here is that the way `GreetProps` is defined, `age` is a required prop when it isn't because of `defaultProps`.
985
972
@@ -1058,7 +1045,7 @@ const el = <TestComponent name="foo" />;
1058
1045
## Misc Discussions and Knowledge
1059
1046
1060
1047
<details>
1061
-
<summary>Why does React.FC break defaultProps?</summary>
1048
+
<summary><b>Why does <code>React.FC</code> break <code>defaultProps</code>?</b></summary>
1062
1049
1063
1050
You can check the discussions here:
1064
1051
@@ -1071,7 +1058,7 @@ This is just the current state and may be fixed in future.
1071
1058
</details>
1072
1059
1073
1060
<details>
1074
-
<summary>TypeScript 2.9 and earlier</summary>
1061
+
<summary><b>TypeScript 2.9 and earlier</b></summary>
1075
1062
1076
1063
For TypeScript 2.9 and earlier, there's more than one way to do it, but this is the best advice we've yet seen:
@@ -1468,11 +1453,7 @@ Of course, if you're making any sort of significant form, [you should use Formik
1468
1453
| SyntheticEvent | The base event for all above events. Should be used when unsure about event type |
1469
1454
1470
1455
<details>
1471
-
<summary>
1472
-
1473
-
**What about `InputEvent`?**
1474
-
1475
-
</summary>
1456
+
<summary><b>What about <code>InputEvent</code>?</b></summary>
1476
1457
1477
1458
You've probably noticed that there is no `InputEvent`. This is because it is not supported by Typescript as the event itself has no fully browser support and may behave differently in different browsers. You can use `KeyboardEvent` instead.
Side note: the `ref` you get from `forwardRef` is mutable so you can assign to it if needed.
1805
-
1806
-
</summary>
1783
+
<summary><b>Side note: the <code>ref</code> you get from <code>forwardRef</code> is mutable so you can assign to it if needed.</b></summary>
1807
1784
1808
1785
This was done [on purpose](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/43265/). You can make it immutable if you have to - assign `React.Ref` if you want to ensure nobody reassigns it:
1809
1786
@@ -2368,9 +2345,7 @@ partialStateUpdate({ foo: 2 }); // this works
2368
2345
```
2369
2346
2370
2347
<details>
2371
-
<summary>
2372
-
Minor caveats on using <code>Partial</code>
2373
-
</summary>
2348
+
<summary><b>Minor caveats on using <code>Partial</code></b></summary>
2374
2349
2375
2350
Note that there are some TS users who don't agree with using `Partial` as it behaves today. See [subtle pitfalls of the above example here](https://twitter.com/ferdaber/status/1084798596027957248), and check out this long discussion on [why @types/react uses Pick instead of Partial](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365).
For instance, the [useDarkMode hook](https://github.com/donavon/use-dark-mode) exports the functions that follows a similar structure.
2531
-
2532
-
</summary>
2503
+
<summary><b>For instance, the <ahref="https://github.com/donavon/use-dark-mode">useDarkMode hook</a> exports the functions that follows a similar structure.</b></summary>
0 commit comments