Skip to content

Commit 3a1b8f2

Browse files
committed
Merge branch 'source' into part0-spanish
2 parents 7b971f6 + 4da2e21 commit 3a1b8f2

File tree

9 files changed

+92
-41
lines changed

9 files changed

+92
-41
lines changed

src/content/1/en/part1c.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ Next, let's make a <i>Button</i> component for the buttons of our application. W
584584
```js
585585
const Button = (props) => {
586586
return (
587-
<button onClick={props.handleClick}>
587+
<button onClick={props.onClick}>
588588
{props.text}
589589
</button>
590590
)
@@ -608,15 +608,15 @@ const App = () => {
608608
<Display counter={counter}/>
609609
// highlight-start
610610
<Button
611-
handleClick={increaseByOne}
611+
onClick={increaseByOne}
612612
text='plus'
613613
/>
614614
<Button
615-
handleClick={setToZero}
615+
onClick={setToZero}
616616
text='zero'
617617
/>
618618
<Button
619-
handleClick={decreaseByOne}
619+
onClick={decreaseByOne}
620620
text='minus'
621621
/>
622622
// highlight-end
@@ -671,9 +671,9 @@ const App = () => {
671671
return (
672672
<div>
673673
<Display counter={counter} />
674-
<Button handleClick={increaseByOne} text="plus" />
675-
<Button handleClick={setToZero} text="zero" />
676-
<Button handleClick={decreaseByOne} text="minus" />
674+
<Button onClick={increaseByOne} text="plus" />
675+
<Button onClick={setToZero} text="zero" />
676+
<Button onClick={decreaseByOne} text="minus" />
677677
</div>
678678
)
679679
}
@@ -720,7 +720,7 @@ We can simplify the Button component as well.
720720
```js
721721
const Button = (props) => {
722722
return (
723-
<button onClick={props.handleClick}>
723+
<button onClick={props.onClick}>
724724
{props.text}
725725
</button>
726726
)
@@ -729,9 +729,24 @@ const Button = (props) => {
729729
730730
We can use destructuring to get only the required fields from <i>props</i>, and use the more compact form of arrow functions:
731731
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`:
736+
737+
```js
738+
const Button = ({ onClick, text }) => (
739+
<button onClick={onClick}>
740+
{text}
741+
</button>
742+
)
743+
```
744+
745+
could also be called as following:
746+
732747
```js
733-
const Button = ({ handleClick, text }) => (
734-
<button onClick={handleClick}>
748+
const Button = ({ onSmash, text }) => (
749+
<button onClick={onSmash}>
735750
{text}
736751
</button>
737752
)
@@ -740,9 +755,9 @@ const Button = ({ handleClick, text }) => (
740755
We can simplify the Button component once more by declaring the return statement in just one line:
741756
742757
```js
743-
const Button = ({ handleClick, text }) => <button onClick={handleClick}>{text}</button>
758+
const Button = ({ onSmash, text }) => <button onSmash={onSmash}>{text}</button>
744759
```
745760
746-
However, be careful to not oversimplify your components, as this makes adding complexity a more tedious task down the road.
761+
**NB**: However, be careful to not oversimplify your components, as this makes adding complexity a more tedious task down the road.
747762
748763
</div>

src/content/1/fr/part1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,7 @@ lang: fr
88

99
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.
1010

11+
<i>Partie mise à jour le 11 août 2023</i>
12+
- <i>Create React App a été remplacé par Vite</i>
13+
1114
</div>

src/content/1/fr/part1c.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const App = (props) => {
191191
export default App
192192
```
193193

194-
Et le fichier <in>index.js</it> devient :
194+
Et le fichier <in>main.js</it> devient :
195195

196196
```js
197197
import React from 'react'
@@ -251,7 +251,7 @@ Jusqu'à présent, tous nos composants étaient simples dans le sens où ils ne
251251

252252
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.
253253

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 à
255255

256256
```js
257257
import React from 'react'
@@ -364,7 +364,10 @@ const App = () => {
364364

365365
Il est facile de suivre les appels effectués à la fonction de rendu du composant <i>App</i> :
366366

367-
![](../../images/1/4e.png)
367+
![Capture d'écran de la fonction de rendu avec les outils de développement.x](../../images/1/4e.png)
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+
368371

369372
### Gestion des événements
370373

@@ -624,9 +627,11 @@ const App = () => {
624627
}
625628
```
626629

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.
628633

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."
630635

631636
### Les changements d'état entraînent un nouveau rendu
632637

@@ -656,7 +661,7 @@ const Display = (props) => {
656661
```
657662

658663
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 :
660665

661666
```js
662667
const Display = ({ counter }) => {
@@ -666,8 +671,7 @@ const Display = ({ counter }) => {
666671
}
667672
```
668673

669-
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 :
671675

672676
```js
673677
const Display = ({ counter }) => <div>{counter}</div>
@@ -685,7 +689,12 @@ const Button = (props) => {
685689
}
686690
```
687691

688-
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` :
689698

690699
```js
691700
const Button = ({ onClick, text }) => (
@@ -695,12 +704,21 @@ const Button = ({ onClick, text }) => (
695704
)
696705
```
697706

698-
Nous pouvons simplifier une fois de plus le composant Button en déclarant l'instruction return sur une seule ligne :
707+
ou encore comme suit :
708+
709+
```js
710+
const Button = ({ onSmash, text }) => (
711+
<button onClick={onSmash}>
712+
{text}
713+
</button>
714+
```
715+
716+
Nous pouvons simplifier une fois de plus le composant Button en déclarant l'instruction de retour en une seule ligne :
699717
700718
```js
701-
const Button = ({ onClick, text }) => <button onClick={onClick}>{text}</button>
719+
const Button = ({ onSmash, text }) => <button onSmash={onSmash}>{text}</button>
702720
```
703721
704-
Cependant, veillez à ne pas trop simplifier vos composants, car cela pourrait rendre la lecture du code plus fastidieuse.
722+
**NB** : Cependant, veillez à ne pas trop simplifier vos composants, car cela rend l'ajout de complexité plus fastidieux par la suite.
705723
706724
</div>

src/content/10/en/part10a.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Now that we are somewhat familiar with the development environment let's enhance
138138
npm install --save-dev eslint @babel/eslint-parser eslint-plugin-react eslint-plugin-react-native
139139
```
140140
141-
Next, let's add the ESLint configuration into a <i>.eslintrc</i> file in the <i>rate-repository-app</i> directory with the following content:
141+
Next, let's add the ESLint configuration into a <i>.eslintrc.json</i> file in the <i>rate-repository-app</i> directory with the following content:
142142
143143
```javascript
144144
{

src/content/4/en/part4c.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const usersRouter = require('./controllers/users')
214214
app.use('/api/users', usersRouter)
215215
```
216216

217-
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:
218218

219219
```js
220220
const bcrypt = require('bcrypt')
@@ -350,7 +350,7 @@ Mongoose does not have a built-in validator for checking the uniqueness of a fie
350350
npm install mongoose-unique-validator
351351
```
352352

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>:
354354

355355
```js
356356
const mongoose = require('mongoose')
@@ -411,7 +411,7 @@ You can find the code for our current application in its entirety in the <i>part
411411

412412
The code for creating a new note has to be updated so that the note is assigned to the user who created it.
413413

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:
415415

416416
```js
417417
const User = require('../models/user') //highlight-line
@@ -486,7 +486,7 @@ We would like our API to work in such a way, that when an HTTP GET request is ma
486486

487487
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.
488488

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>:
490490

491491
```js
492492
usersRouter.get('/', async (request, response) => {
@@ -520,7 +520,7 @@ The result is now exactly like we want it to be:
520520

521521
![combined data showing no repetition](../../images/4/14new.png)
522522

523-
Let's also add a suitable population of user information to notes:
523+
Let's also add a suitable population of user information to notes in <i>controllers/notes.js</i>:
524524

525525
```js
526526
notesRouter.get('/', async (request, response) => {

src/content/4/en/part4d.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ Usernames, passwords and applications using token authentication must always be
347347

348348
We will implement login to the frontend in the [next part](/en/part5).
349349

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+
350352
</div>
351353

352354
<div class="tasks">
@@ -412,7 +414,7 @@ Modify adding new blogs so that it is only possible if a valid token is sent wit
412414

413415
#### 4.20*: bloglist expansion, step8
414416

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>.
416418

417419
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.
418420

@@ -489,8 +491,11 @@ blogsRouter.delete('/:id', async (request, response) => {
489491
Note that it is possible to register a middleware only for a specific set of routes. So instead of using _userExtractor_ with all the routes,
490492

491493
```js
494+
const middleware = require('../utils/middleware');
495+
// ...
496+
492497
// use the middleware in all routes
493-
app.use(userExtractor) // highlight-line
498+
app.use(middleware.userExtractor) // highlight-line
494499

495500
app.use('/api/blogs', blogsRouter)
496501
app.use('/api/users', usersRouter)
@@ -500,16 +505,22 @@ app.use('/api/login', loginRouter)
500505
we could register it to be only executed with path <i>/api/blogs</i> routes:
501506

502507
```js
508+
const middleware = require('../utils/middleware');
509+
// ...
510+
503511
// use the middleware only in /api/blogs routes
504-
app.use('/api/blogs', userExtractor, blogsRouter) // highlight-line
512+
app.use('/api/blogs', middleware.userExtractor, blogsRouter) // highlight-line
505513
app.use('/api/users', usersRouter)
506514
app.use('/api/login', loginRouter)
507515
```
508516

509517
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:
510518

511519
```js
512-
router.post('/', userExtractor, async (request, response) => {
520+
const middleware = require('../utils/middleware');
521+
// ...
522+
523+
router.post('/', middleware.userExtractor, async (request, response) => {
513524
// ...
514525
}
515526
```

src/content/6/en/part6d.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ import { getNotes, createNote } from './requests'
224224
const App = () => {
225225
const queryClient = useQueryClient() // highlight-line
226226

227-
const newNoteMutation = useMutation(createNote, {
227+
const newNoteMutation = useMutation({
228+
mutationFn: createNote,
228229
onSuccess: () => { // highlight-line
229230
queryClient.invalidateQueries({ queryKey: ['notes'] }) // highlight-line
230231
},
@@ -258,7 +259,8 @@ import { getNotes, createNote, updateNote } from './requests' // highlight-line
258259
const App = () => {
259260
// ...
260261

261-
const updateNoteMutation = useMutation(updateNote, {
262+
const updateNoteMutation = useMutation({
263+
mutationFn: updateNote,
262264
onSuccess: () => {
263265
queryClient.invalidateQueries({ queryKey: ['notes'] })
264266
},
@@ -281,7 +283,8 @@ The current code for the application is in [GitHub](https://github.com/fullstack
281283
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:
282284

283285
```js
284-
const updateNoteMutation = useMutation(updateNote, {
286+
const updateNoteMutation = useMutation({
287+
mutationFn: updateNote,
285288
onSuccess: () => {
286289
queryClient.invalidateQueries('notes') // highlight-line
287290
},
@@ -302,7 +305,8 @@ The change for the mutation adding a new note is as follows:
302305
const App = () => {
303306
const queryClient = useQueryClient()
304307

305-
const newNoteMutation = useMutation(createNote, {
308+
const newNoteMutation = useMutation({
309+
mutationFn: createNote,
306310
onSuccess: (newNote) => {
307311
const notes = queryClient.getQueryData(['notes']) // highlight-line
308312
queryClient.setQueryData(['notes'], notes.concat(newNote)) // highlight-line
@@ -564,7 +568,7 @@ const App = () => {
564568

565569
return (
566570
<CounterContext.Provider value={[counter, counterDispatch]}> // highlight-line
567-
<Display counter={counter}/>
571+
<Display />
568572
<div>
569573
<Button type='INC' label='+' />
570574
<Button type='DEC' label='-' />

src/content/7/en/part7d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ When using CSS, we have to use [css](https://webpack.js.org/loaders/css-loader/)
463463
use: ['style-loader', 'css-loader'],
464464
},
465465
// highlight-end
466-
];
466+
],
467467
}
468468
```
469469

src/content/9/en/part9d.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ const App = () => {
587587
}
588588
```
589589
590-
When we hover over the *useState* calls in the editor, we notice couple of interesting things.
590+
When we hover over the *useState* calls in the editor, we notice a couple of interesting things.
591591
592592
The type of the first call *useState('')* looks like the following:
593593

0 commit comments

Comments
 (0)