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
@@ -720,7 +720,7 @@ We can simplify the Button component as well.
720
720
```js
721
721
constButton= (props) => {
722
722
return (
723
-
<button onClick={props.handleClick}>
723
+
<button onClick={props.onClick}>
724
724
{props.text}
725
725
</button>
726
726
)
@@ -729,9 +729,24 @@ const Button = (props) => {
729
729
730
730
We can use destructuring to get only the required fields from <i>props</i>, and use the more compact form of arrow functions:
731
731
732
+
**NB**: While building your own components, you can name their event handler props anyway you like, for this you can refer to the react's documnetion on [Naming event handler props](https://react.dev/learn/responding-to-events#naming-event-handler-props). It goes as following:
733
+
734
+
> By convention, event handler props should start with `on`, followed by a capital letter.
735
+
For example, the Button component’s `onClick` prop could have been called `onSmash`:
Copy file name to clipboardExpand all lines: src/content/1/fr/part1.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,4 +8,7 @@ lang: fr
8
8
9
9
Dans cette partie, nous nous familiariserons avec la bibliothèque React, que nous utiliserons pour écrire le code qui s'exécute dans le navigateur. Nous examinerons également certaines fonctionnalités de JavaScript qui sont importantes pour comprendre React.
Copy file name to clipboardExpand all lines: src/content/1/fr/part1c.md
+30-12Lines changed: 30 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,7 +191,7 @@ const App = (props) => {
191
191
exportdefaultApp
192
192
```
193
193
194
-
Et le fichier <in>index.js</it> devient :
194
+
Et le fichier <in>main.js</it> devient :
195
195
196
196
```js
197
197
importReactfrom'react'
@@ -251,7 +251,7 @@ Jusqu'à présent, tous nos composants étaient simples dans le sens où ils ne
251
251
252
252
Ensuite, ajoutons un état au composant <i>App</i> de notre application à l'aide du [state hook](https://reactjs.org/docs/hooks-state.html) de React.
253
253
254
-
Nous allons modifier l'application comme suit. <i>index.js</i> revient à
254
+
Nous allons modifier l'application comme suit. <i>main.js</i> revient à
255
255
256
256
```js
257
257
importReactfrom'react'
@@ -364,7 +364,10 @@ const App = () => {
364
364
365
365
Il est facile de suivre les appels effectués à la fonction de rendu du composant <i>App</i> :
366
366
367
-

367
+

368
+
369
+
Votre console de navigateur était-elle ouverte ? Si ce n'était pas le cas, promettez que ce sera la dernière fois qu'on vous le rappellera.
370
+
368
371
369
372
### Gestion des événements
370
373
@@ -624,9 +627,11 @@ const App = () => {
624
627
}
625
628
```
626
629
627
-
Puisque nous avons maintenant un composant <i>Button</i> facilement réutilisable, nous avons également implémenté de nouvelles fonctionnalités dans notre application en ajoutant un bouton qui peut être utilisé pour décrémenter le compteur.
630
+
Étant donné que nous avons maintenant un composant <i>Button</i> facilement réutilisable, nous avons également implémenté une nouvelle fonctionnalité dans notre application en ajoutant un bouton qui peut être utilisé pour décrémenter le compteur.
631
+
632
+
Le gestionnaire d'événements est passé au composant <i>Button</i> via la prop _handleClick_. Le nom de la prop en lui-même n'est pas très significatif, mais notre choix de nom n'était pas complètement aléatoire.
628
633
629
-
Le gestionnaire d'événements est transmis au composant <i>Button</i> via la prop _onClick_. Le nom de la prop lui-même n'est pas assez significatif, mais notre choix de nom n'était pas complètement aléatoire. Le [tutoriel](https://reactjs.org/tutorial/tutorial.html) officiel de React suggère cette convention.
634
+
Le [tutoriel](https://react.dev/learn/tutorial-tic-tac-toe) officiel de React suggère : "En React, il est conventionnel d'utiliser des noms de type onSomething pour les props qui représentent des événements et handleSomething pour les définitions de fonctions qui gèrent ces événements."
630
635
631
636
### Les changements d'état entraînent un nouveau rendu
632
637
@@ -656,7 +661,7 @@ const Display = (props) => {
656
661
```
657
662
658
663
Le composant utilise uniquement le champ _counter_ de ses <i>props</i>.
659
-
Cela signifie que nous pouvons simplifier le composant en utilisant la [déstructuration](/fr/part1/etat_des_composants_gestionnaires_devenements#destructuration), comme ceci:
664
+
Cela signifie que nous pouvons simplifier le composant en utilisant [la destructuration](/fr/part1/etat_des_composants_gestionnaires_devenements#destructuration), comme ceci:
La fonction définissant le composant ne contient que l'instruction return, donc
670
-
nous pouvons définir la fonction en utilisant la forme plus compacte des fonctions fléchées :
674
+
La fonction qui définit le composant ne contient que l'instruction de retour, nous pouvons donc définir la fonction en utilisant la forme plus compacte des fonctions fléchées :
Nous pouvons utiliser la déstructuration pour obtenir uniquement les champs requis à partir de <i>props</i>, et utiliser la forme plus compacte des fonctions fléchées :
692
+
Nous pouvons utiliser la destructuration pour obtenir uniquement les champs requis des <i>props</i> et utiliser la forme plus compacte des fonctions fléchées :
693
+
694
+
**NB** : Lors de la création de vos propres composants, vous pouvez nommer les props des gestionnaires d'événements comme bon vous semble, pour cela, vous pouvez vous référer à la documentation de React sur [Naming event handler props](https://react.dev/learn/responding-to-events#naming-event-handler-props). Cela se présente comme suit :
695
+
696
+
> Par convention, les props des gestionnaires d'événements doivent commencer par `on`, suivi d'une lettre majuscule.
697
+
Par exemple, la prop `onClick` du composant Button aurait pu s'appeler `onSmash` :
The contents of the file that defines the router are as follows:
217
+
The contents of the file, <i>controllers/users.js</i>, that defines the router are as follows:
218
218
219
219
```js
220
220
constbcrypt=require('bcrypt')
@@ -350,7 +350,7 @@ Mongoose does not have a built-in validator for checking the uniqueness of a fie
350
350
npm install mongoose-unique-validator
351
351
```
352
352
353
-
and extend the code by following the library documentation:
353
+
and extend the code by following the library documentation in <i>models/user.js</i>:
354
354
355
355
```js
356
356
constmongoose=require('mongoose')
@@ -411,7 +411,7 @@ You can find the code for our current application in its entirety in the <i>part
411
411
412
412
The code for creating a new note has to be updated so that the note is assigned to the user who created it.
413
413
414
-
Let's expand our current implementation so that the information about the user who created a note is sent in the <i>userId</i> field of the request body:
414
+
Let's expand our current implementation in <i>controllers/notes.js</i> so that the information about the user who created a note is sent in the <i>userId</i> field of the request body:
@@ -486,7 +486,7 @@ We would like our API to work in such a way, that when an HTTP GET request is ma
486
486
487
487
As previously mentioned, document databases do not properly support join queries between collections, but the Mongoose library can do some of these joins for us. Mongoose accomplishes the join by doing multiple queries, which is different from join queries in relational databases which are <i>transactional</i>, meaning that the state of the database does not change during the time that the query is made. With join queries in Mongoose, nothing can guarantee that the state between the collections being joined is consistent, meaning that if we make a query that joins the user and notes collections, the state of the collections may change during the query.
488
488
489
-
The Mongoose join is done with the [populate](http://mongoosejs.com/docs/populate.html) method. Let's update the route that returns all users first:
489
+
The Mongoose join is done with the [populate](http://mongoosejs.com/docs/populate.html) method. Let's update the route that returns all users first in <i>controllers/users.js</i>:
Copy file name to clipboardExpand all lines: src/content/4/en/part4d.md
+15-4Lines changed: 15 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -347,6 +347,8 @@ Usernames, passwords and applications using token authentication must always be
347
347
348
348
We will implement login to the frontend in the [next part](/en/part5).
349
349
350
+
NOTE: At this stage, in the deployed notes app, it is expected that the creating a note feature will stop working as the backend login feature is not yet linked to the frontend.
351
+
350
352
</div>
351
353
352
354
<divclass="tasks">
@@ -412,7 +414,7 @@ Modify adding new blogs so that it is only possible if a valid token is sent wit
412
414
413
415
#### 4.20*: bloglist expansion, step8
414
416
415
-
[This example](/en/part4/token_authentication) from part 4 shows taking the token from the header with the _getTokenFrom_ helper function.
417
+
[This example](/en/part4/token_authentication) from part 4 shows taking the token from the header with the _getTokenFrom_ helper function in <i>controllers/blogs.js</i>.
416
418
417
419
If you used the same solution, refactor taking the token to a [middleware](/en/part3/node_js_and_express#middleware). The middleware should take the token from the <i>Authorization</i> header and place it into the <i>token</i> field of the <i>request</i> object.
As can be seen, this happens by chaining multiple middlewares as the parameter of function <i>use</i>. It would also be possible to register a middleware only for a specific operation:
@@ -281,7 +283,8 @@ The current code for the application is in [GitHub](https://github.com/fullstack
281
283
The application works well, and the code is relatively simple. The ease of making changes to the list of notes is particularly surprising. For example, when we change the importance of a note, invalidating the query <i>notes</i> is enough for the application data to be updated:
0 commit comments