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: src/content/10/en/part10.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,6 @@ In this part, we will learn how to build native Android and iOS mobile applicati
10
10
11
11
<i>Part updated 26th Feb 2024</i>
12
12
- <i>New Node 20 version of rate-repository-api</i>
13
-
- <i>Material updated in parts 10a, 10b and 10c</i>
14
-
15
-
Note: Some updates are not compatible anymore with material before Feb 2024.
16
-
We recommend a fresh start with this new Part 10 material you're reading now. However, if you´re returning to this course after a break, and you want to continue the exercises in your older project, please use [Part 10 material before the update](https://github.com/fullstack-hy2020/fullstack-hy2020.github.io/tree/e9784f36de8a0badc28fabde49e33e2959479177/src/content/10/en).
Copy file name to clipboardExpand all lines: src/content/10/en/part10b.md
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,6 @@ lang: en
7
7
8
8
<divclass="content">
9
9
10
-
Note: This course material was updated in Feb 2024. Some updates are not compatible anymore with older material.
11
-
We recommend a fresh start with this new Part 10 material. However, if you´re returning to this course after a break, and you want to continue the exercises in your older project, please use [Part 10 material before the upgrade](https://github.com/fullstack-hy2020/fullstack-hy2020.github.io/tree/e9784f36de8a0badc28fabde49e33e2959479177/src/content/10/en).
12
-
13
-
14
10
Now that we have set up our development environment we can get into React Native basics and get started with the development of our application. In this section, we will learn how to build user interfaces with React Native's core components, how to add style properties to these core components, how to transition between views, and how to manage the form's state efficiently.
Copy file name to clipboardExpand all lines: src/content/10/en/part10c.md
-3Lines changed: 0 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,6 @@ lang: en
7
7
8
8
<divclass="content">
9
9
10
-
Note: This course material was updated in Feb 2024. Some updates are not compatible anymore with older material.
11
-
We recommend a fresh start with this new Part 10 material. However, if you´re returning to this course after a break, and you want to continue the exercises in your older project, please use [Part 10 material before the upgrade](https://github.com/fullstack-hy2020/fullstack-hy2020.github.io/tree/e9784f36de8a0badc28fabde49e33e2959479177/src/content/10/en).
12
-
13
10
So far we have implemented features to our application without any actual server communication. For example, the reviewed repositories list we have implemented uses mock data and the sign in form doesn't send the user's credentials to any authentication endpoint. In this section, we will learn how to communicate with a server using HTTP requests, how to use Apollo Client in a React Native application, and how to store data in the user's device.
14
11
15
12
Soon we will learn how to communicate with a server in our application. Before we get to that, we need a server to communicate with. For this purpose, we have a completed server implementation in the [rate-repository-api](https://github.com/fullstack-hy2020/rate-repository-api) repository. The rate-repository-api server fulfills all our application's API needs during this part. It uses [SQLite](https://www.sqlite.org/index.html) database which doesn't need any setup and provides an Apollo GraphQL API along with a few REST API endpoints.
Copy file name to clipboardExpand all lines: src/content/5/en/part5c.md
-6Lines changed: 0 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,6 @@ letter: c
5
5
lang: en
6
6
---
7
7
8
-
<divclass="tasks">
9
-
10
-
The test library used in this part was changed on March 3, 2024 from Jest to Vitest. If you already started this part using Jest, you can see [here](https://github.com/fullstack-hy2020/fullstack-hy2020.github.io/blob/02d8be28b1c9190f48976fbbd2435b63261282df/src/content/5/en/part5c.md) the old content.
11
-
12
-
</div>
13
-
14
8
<divclass="content">
15
9
16
10
There are many different ways of testing React applications. Let's take a look at them next.
Copy file name to clipboardExpand all lines: src/content/9/en/part9d.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -222,7 +222,7 @@ export default App;
222
222
223
223
and remove the unnecessary files.
224
224
225
-
The whole app is now in one component. That is not what we want, so refactor the code so that it consists of three components: *Header*, *Content* and *Total*. All data is still kept in the *App* component, which passes all necessary data to each component as props. *Be sure to add type declarations for each component's props!*
225
+
The whole app is now in one component. That is not what we want, so refactor the code so that it consists of three components: *Header*, *Content* and *Total*. All data is still kept in the *App* component, which passes all necessary data to each component as props. <i>Be sure to add type declarations for each component's props!</i>
226
226
227
227
The *Header* component should take care of rendering the name of the course. *Content* should render the names of the different parts and the number of exercises in each part, and *Total* should render the total sum of exercises in all parts.
228
228
@@ -409,15 +409,15 @@ If we try to access the objects in the array *courseParts: CoursePart[]* we noti
409
409
410
410
And indeed, the TypeScript [documentation](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#working-with-union-types) says this:
411
411
412
-
> *TypeScript will only allow an operation (or attribute access) if it is valid for every member of the union.*
412
+
> <i>TypeScript will only allow an operation (or attribute access) if it is valid for every member of the union.</i>
413
413
414
414
The documentation also mentions the following:
415
415
416
-
> *The solution is to narrow the union with code... Narrowing occurs when TypeScript can deduce a more specific type for a value based on the structure of the code.*
416
+
> <i>The solution is to narrow the union with code... Narrowing occurs when TypeScript can deduce a more specific type for a value based on the structure of the code.</i>
417
417
418
418
So once again the [type narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html) is the rescue!
419
419
420
-
One handy way to narrow these kinds of types in TypeScript is to use *switch case* expressions. Once TypeScript has inferred that a variable is of union type and that each type in the union contain a certain literal attribute (in our case *kind*), we can use that as a type identifier. We can then build a switch case around that attribute and TypeScript will know which attributes are available within each case block:
420
+
One handy way to narrow these kinds of types in TypeScript is to use *switch case* expressions. Once TypeScript has inferred that a variable is of union type and that each type in the union contains a certain literal attribute (in our case *kind*), we can use that as a type identifier. We can then build a switch case around that attribute and TypeScript will know which attributes are available within each case block:
421
421
422
422

423
423
@@ -665,7 +665,7 @@ import { useState } from "react";
665
665
666
666
constApp= () => {
667
667
const [notes, setNotes] = useState<Note[]>([
668
-
{ id:1, content:'testing' } // highlight-line
668
+
{ id:'1', content:'testing' } // highlight-line
669
669
]);
670
670
const [newNote, setNewNote] =useState('');
671
671
@@ -847,7 +847,7 @@ We can now set the data in the state *notes* to get the code working:
847
847
848
848
So just like with *useState*, we gave a type parameter to *axios.get* to instruct it on how the typing should be done. Just like *useState* also *axios.get* is a [generic function](https://www.typescriptlang.org/docs/handbook/2/generics.html#working-with-generic-type-variables). Unlike some generic functions, the type parameter of *axios.get* has a default value of *any* so, if the function is used without defining the type parameter, the type of the response data will be any.
849
849
850
-
The code works, compiler and Eslint are happy and remain quiet. However, giving a type parameter to *axios.get* is a potentially dangerous thing to do. The response body can contain data in an arbitrary form, and when giving a type parameter we are essentially just telling to TypeScript compiler to trust us that the data has type *Note[]*.
850
+
The code works, compiler and Eslint are happy and remain quiet. However, giving a type parameter to *axios.get* is a potentially dangerous thing to do. The <i>response body can contain data in an arbitrary form</i>, and when giving a type parameter we are essentially just telling to TypeScript compiler to trust us that the data has type *Note[]*.
851
851
852
852
So our code is essentially as safe as it would be if a [type assertion](/en/part9/first_steps_with_type_script#type-assertion) would be used:
853
853
@@ -860,9 +860,9 @@ So our code is essentially as safe as it would be if a [type assertion](/en/part
860
860
}, [])
861
861
```
862
862
863
-
Since the TypeScript types do not even exist in runtime, our code does not give us any "safety" against situations where the request body contains data in a wrong form.
863
+
Since the TypeScript types do not even exist in runtime, our code does not give us any safety against situations where the request body contains data in the wrong form.
864
864
865
-
Giving a type parameter to *axios.get* might be ok if we are *absolutely sure* that the backend behaves correctly and returns always the data in the correct form. If we want to build a robust system we should prepare for surprises and parse the response data in the frontend, similarly to what we did [in the previous section](/en/part9/typing_an_express_app#proofing-requests) for the requests to the backend.
865
+
Giving a type parameter to *axios.get* might be ok if we are <i>absolutely sure</i> that the backend behaves correctly and returns always the data in the correct form. If we want to build a robust system we should prepare for surprises and parse the response data in the frontend, similarly to what we did [in the previous section](/en/part9/typing_an_express_app#proofing-requests) for the requests to the backend.
866
866
867
867
Let us now wrap up our app by implementing the new note addition:
0 commit comments