Skip to content

Commit 766fa1c

Browse files
Updated README on 2022-02-19T00:27:55.555Z
1 parent f049a47 commit 766fa1c

File tree

1 file changed

+15
-44
lines changed

1 file changed

+15
-44
lines changed

README.md

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ Local dev setups:
219219
- [TSDX](https://tsdx.io/): `npx tsdx create mylib` for Creating React+TS _libraries_. (in future: [TurboRepo](https://twitter.com/jaredpalmer/status/1346217789942591488))
220220

221221
<details>
222-
<summary>
223-
Other tools
224-
</summary>
222+
<summary><b>Other tools</b></summary>
225223

226224
Less mature tools still worth checking out:
227225

@@ -255,7 +253,7 @@ import ReactDOM from "react-dom";
255253

256254
<details>
257255

258-
<summary>Explanation</summary>
256+
<summary><b>Explanation</b></summary>
259257

260258
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>
261259

@@ -305,7 +303,7 @@ const App = ({ message }: { message: string }) => <div>{message}</div>;
305303
306304
<details>
307305

308-
<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>
309307

310308
You may see this in many React+TypeScript codebases:
311309

@@ -335,7 +333,7 @@ const Title: React.FunctionComponent<{ title: string }> = ({
335333
```
336334

337335
<details>
338-
<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>
339337

340338
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`).
341339

@@ -490,7 +488,7 @@ function Counter() {
490488

491489
<details>
492490

493-
<summary><b>Usage with `Reducer` from `redux`</b></summary>
491+
<summary><b>Usage with <code>Reducer</code> from <code>redux</code></b></summary>
494492

495493
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.
496494

@@ -526,9 +524,7 @@ function DelayedEffect(props: { timerMs: number }) {
526524
```
527525

528526
<details>
529-
<summary>
530-
Solution to the above example
531-
</summary>
527+
<summary><b>Solution to the above example</b></summary>
532528

533529
```tsx
534530
function DelayedEffect(props: { timerMs: number }) {
@@ -586,12 +582,7 @@ doSomethingWith(divRef.current);
586582
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.
587583

588584
<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>
595586

596587
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:
597588

@@ -975,11 +966,7 @@ let el = <Greet age={3} />;
975966
```
976967

977968
<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>
983970

984971
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`.
985972

@@ -1058,7 +1045,7 @@ const el = <TestComponent name="foo" />;
10581045
## Misc Discussions and Knowledge
10591046

10601047
<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>
10621049

10631050
You can check the discussions here:
10641051

@@ -1071,7 +1058,7 @@ This is just the current state and may be fixed in future.
10711058
</details>
10721059

10731060
<details>
1074-
<summary>TypeScript 2.9 and earlier</summary>
1061+
<summary><b>TypeScript 2.9 and earlier</b></summary>
10751062

10761063
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:
10771064

@@ -1187,9 +1174,7 @@ export declare interface AppProps {
11871174
```
11881175

11891176
<details>
1190-
<summary>
1191-
Small `React.ReactNode` edge case
1192-
</summary>
1177+
<summary><b>Small <code>React.ReactNode</code> edge case</b></summary>
11931178

11941179
This code typechecks but has a runtime error:
11951180

@@ -1468,11 +1453,7 @@ Of course, if you're making any sort of significant form, [you should use Formik
14681453
| SyntheticEvent | The base event for all above events. Should be used when unsure about event type |
14691454

14701455
<details>
1471-
<summary>
1472-
1473-
**What about `InputEvent`?**
1474-
1475-
</summary>
1456+
<summary><b>What about <code>InputEvent</code>?</b></summary>
14761457

14771458
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.
14781459

@@ -1799,11 +1780,7 @@ export const FancyButton = React.forwardRef<Ref, Props>((props, ref) => (
17991780
```
18001781

18011782
<details>
1802-
<summary>
1803-
1804-
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>
18071784

18081785
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:
18091786

@@ -2368,9 +2345,7 @@ partialStateUpdate({ foo: 2 }); // this works
23682345
```
23692346

23702347
<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>
23742349

23752350
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).
23762351

@@ -2525,11 +2500,7 @@ declare module 'use-untyped-hook' {
25252500
```
25262501

25272502
<details>
2528-
<summary>
2529-
2530-
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 <a href="https://github.com/donavon/use-dark-mode">useDarkMode hook</a> exports the functions that follows a similar structure.</b></summary>
25332504

25342505
```js
25352506
// inside src/index.js

0 commit comments

Comments
 (0)