Skip to content

Commit 19ad401

Browse files
authored
Merge pull request #3905 from leburgeon/patch-8
Update part9d.md
2 parents 7c68172 + 2b31aee commit 19ad401

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/content/9/en/part9d.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,18 +616,18 @@ The type of the returned array is the following:
616616
617617
So the first element, assigned to *newNote* is a string and the second element that we assigned *setNewNote* has a slightly more complex type. We notice that there is a string mentioned there, so we know that it must be the type of a function that sets a valued data. See [here](https://codewithstyle.info/Using-React-useState-hook-with-TypeScript/) if you want to learn more about the types of useState function.
618618
619-
From this all we see that TypeScript has indeed [inferred](https://www.typescriptlang.org/docs/handbook/type-inference.html#handbook-content) the type of the first useState quite right, it is creating a state with type string.
619+
From all this we see that TypeScript has indeed [inferred](https://www.typescriptlang.org/docs/handbook/type-inference.html#handbook-content) the type of the first useState correctly, a state with type string is created.
620620
621-
When we look at the second useState that has the initial value *[]* the type looks quite different
621+
When we look at the second useState that has the initial value *[]* , the type looks quite different
622622
623623
```ts
624624
useState<never[]>(initialState: never[] | (() => never[])):
625625
[never[], React.Dispatch<React.SetStateAction<never[]>>]
626626
```
627627
628-
TypeScript can just infer that the state has type *never[]*, it is an array but it has no clue what are the elements stored to array, so we clearly need to help the compiler and provide the type explicitly.
628+
TypeScript can just infer that the state has type *never[]*, it is an array but it has no clue what the elements stored to the array are, so we clearly need to help the compiler and provide the type explicitly.
629629
630-
One of the best sources for information about typing React is the [React TypeScript Cheatsheet](https://react-typescript-cheatsheet.netlify.app/). The Cheatsheet chapter about [useState](https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/hooks#usestate) hook instructs to use a *type parameter* in situations where the compiler can not infer the type.
630+
One of the best sources for information about typing React is the [React TypeScript Cheatsheet](https://react-typescript-cheatsheet.netlify.app/). The Cheatsheet chapter about [useState](https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/hooks#usestate) hook instructs us to use a *type parameter* in situations where the compiler can not infer the type.
631631
632632
Let us now define a type for notes:
633633
@@ -644,7 +644,7 @@ The solution is now simple:
644644
const [notes, setNotes] = useState<Note[]>([]);
645645
```
646646
647-
And indeed, the type is set quite right:
647+
And indeed, the type is set correctly:
648648
649649
```ts
650650
useState<Note[]>(initialState: Note[] | (() => Note[])):

0 commit comments

Comments
 (0)