Pratique du Shadowing: Next.js in 100 Seconds // Plus Full Beginner's Tutorial - Apprendre l'anglais à l'oral avec la vidéo

Choisissez un mode d'entraînement

Chaque mode ouvre une salle d'entraînement en plein écran.

163 phrases
Si les phrases sont trop courtes ou trop longues, cliquez sur Edit pour les ajuster.
1
Next .js, create fast, search engine optimized
2
React apps with zero configuration.
3
A traditional React app is rendered client -side, where the browser starts with a shell of an HTML page lacking any rendered content.
4
From there, the browser fetches the JavaScript file containing the React code to render content to the page and make it interactive.
5
But there are two major drawbacks with client -side rendering.
6
One, the content is not reliably indexed by all search engines or read by social media linkbots.
7
And two, it can take longer to reach the first contentful paint when a user first lands on the web page.
8
Next is a framework that allows you to build a React app, but render the content in advance on the server,
9
so the first thing a user or a search bot sees is the fully rendered HTML.
10
After receiving this initial page, client -side rendering takes over, and it works just like a traditional React app.
11
It's the best of both worlds.
12
Fully rendered content for bots, highly interactive content for users.
13
Inside of a Next project, you have a Pages directory.
14
Each JavaScript file defined here exports a React component that represents a route in the application.
15
In other words, the file structure here mirrors the actual URLs that the user will navigate to,
16
and Next provides its own router to make navigation seamless.
17
But the real magic comes into play when we talk about data fetching, because Next can perform multiple server rendering strategies from a single project.
18
Static generation, or pre -rendering, allows you to render your pages at build time.
19
Each page or component can implement a function called getStaticProps.
20
It might fetch data from a cloud database, then pass the data as props to the component.
21
You can then build your app to render out all the HTML locally
22
and upload it to a storage bucket where it can be easily cached by a CDN.
23
That works great for a blog or any kind of app where the data doesn't change often.
24
But if the data does change often, you can implement server -side rendering, which builds the HTML page each time it's requested by the user.
25
In the component, we implement data fetching with the getServerSideProps function.
26
Instead of running at build time, this function runs at request time.
27
That means the page will fetch the latest data on the server each time a new request comes in.
28
That's great for pages with rapidly changing data, but maybe you want something in between.
29
Yet another option is incremental static regeneration.
30
By simply adding a revalidate option to get static props, Next can regenerate a page whenever a new request comes in within a certain time interval.
31
This has been Next .js in 100 seconds.
32
If you want to see more short videos like this, make sure to subscribe and hit the like button.
33
Then open up VS Code and get ready to go beyond 100 seconds with a full breakdown of Next.
34
Before we get going, I'd like to point out that I'm working on a full
35
React Next Firebase course, which I hope to have finally finished by the end of January, which will be available to Fireship Pro members.
36
My goal over the next few minutes is to teach you the fundamentals of Next
37
while also explaining the complexities of server side rendering.
38
To follow along, open up the terminal and run npx create next app followed by the name of your app.
39
And if you get lost at any point, make sure to grab the source code on GitHub or Fireship IO.
40
Let's open up the project in VS Code and then go into the package .json file.
41
In development, the only script we need to worry about is dev, which you can execute by running npm run dev from the command line,
42
which will run our app on localhost 3000.
43
That should give you the default boilerplate in the browser.
44
Now before we get into the React code, there's a few things that I want to point out.
45
First, in the styles directory here, you'll notice how
46
Next supports CSS modules.
47
In the globals file, you can define styles that apply to the entire application.
48
But in other files with .module, you can define classes that only apply to a specific route or component.
49
And you don't have to worry about coming up with a bunch of unique class names
50
or naming conventions when managing your styles.
51
If you want to use styles from a certain module, you just import the style sheet in your JavaScript,
52
then reference your styles in JSX as if the styles were a JavaScript object.
53
That's pretty awesome, but from there, let's shift our attention over to the pages directory.
54
Inside this directory, we define all of the pages and routes for the application.
55
At the highest level, we have this underscore app .js file, which is like the main entry point into the app.
56
In other words, every individual page will start from this template.
57
Currently, the application only has one page, which points to the root URL and is defined by the component in the index .js file.
58
When a user navigates to this URL, next will find the default export, which is a React component, in this file.
59
So every file or page in your application needs to have one default export.
60
To demonstrate this further, let's create our first route.
61
In the pages directory, create a new file called hello .js.
62
Then we can define the content of this page by exporting
63
a default react component from it from there we can go back to the browser
64
and navigate to localhost 3000 slash hello and we should get the content of
65
that component congratulations you just built your first web page with next
66
but now let's imagine a route that's a little more complex we have a cars route
67
that should show a list of cars then an infinite number of cars
68
that might be dynamically generated under that url we can implement a dynamic route like that by first creating a cars directory.
69
Then inside the directory, we'll add an index .js file.
70
which will show the main list of cars.
71
Then for each individual car, we'll add a component that has a file name of brackets param name dot j s.
72
The brackets make this route dynamic, which means anytime a user navigates to cars slash whatever, or cars slash
73
Tesla, it will render the component in this file.
74
To see that in action, let's go ahead and implement the component logic.
75
In the index file, we'll just add a placeholder for the cars list for now.
76
But in the dynamic component, we'll import the useRouter hook from the next router.
77
It allows us to access the query parameters from the URL.
78
In this example, the value is ID, but you can give it a name of whatever you want.
79
And then we'll render that value out to the template.
80
Now back in the browser, if we go to the cars URL, it renders out the cars component.
81
Then if we add any string after the cars URL, it renders out the dynamic component.
82
Now one other thing you may have noticed in the pages directory is this API directory.
83
So what is that all about?
84
The API directory is a special part of Next for setting up routes that will only apply to the server.
85
That can be useful because the code you write here won't increase the client -side JavaScript bundle
86
that needs to ultimately be sent over the network.
87
We're not going to get into API routes in this video,
88
but just know that it's a useful feature when you have work that needs to be done on the backend,
89
or if you simply want to expose an API for your end users.
90
But now, let's shift our attention over to the most valuable feature in Next, which of course is data fetching.
91
Next allows us to fetch data and render HTML on the server.
92
And again, the benefit of doing that is
93
that the end user gets rendered content quicker
94
and the content can be reliably crawled by search bots and social media link bots.
95
Now, when it comes to server rendering, there are two main options, static generation and server -side rendering.
96
Static generation is also called pre -rendering because you generate all the HTML at build time.
97
It makes life very simple because you generate a bunch of HTML files, then upload them to a storage bucket or static host,
98
and they can be delivered with very high performance over a CDN.
99
But there's a couple of big trade -offs here.
100
The first one is that your data may become stale.
101
If the data on the server changes, you need to rebuild and redeploy your site in order for those changes to be reflected.
102
Another important trade -off to think about is scale.
103
If your website has a million pages, it'll be very slow and difficult to pre -render all of them.
104
That makes static generation most well -suited for data
105
that doesn't change often and for sites that have a relatively low number of total pages.
106
A good example would be a blog, because it might have a few hundred pages and those pages likely don't change on a daily basis.
107
Let's go ahead and take a look at how we might implement static generation in Next.
108
In the car component, let's imagine we need to fetch data from an external source, like a database or API.
109
To simulate that for the demo, I've added a couple of JSON files to the public directory.
110
We have a file that returns an array of IDs, then an individual response for each car,
111
which contains an image and other data about the car.
112
Now we can fetch this data for the car component by implementing the get static props function inside the component file.
113
When you build your site, Next will automatically call this function, then send the result as props to the component itself.
114
What we want to do here is fetch the JSON for an individual car
115
so it can be used in the HTML or UI for the car page.
116
In this case, we need the ID from the URL to know which car was requested.
117
We can get that information from the params argument in the function.
118
Then from there, we'll use the fetch API to make a request to localhost to request the JSON file with that ID.
119
We can then convert it to JSON.
120
Then the final step is to return an object that has a props property, where each prop can then be accessed by the component.
121
Up in the component code, we can destructure the car prop and then use it in the JSX,
122
which I'm doing here by adding an image tag, which relies on the data fetched by the server as the image source.
123
Now if you're concerned about search engine optimization,
124
you likely want to add an SEO -friendly title as well as meta tags to the head of the document.
125
Next makes that very easy to accomplish by simply importing the head component.
126
Anything inside this component will be rendered out to the head of the document.
127
Like in this case, we add a title with the car color and ID.
128
And we could also add meta tags for Twitter and Facebook cards if we wanted to.
129
Now because we're working with a dynamic route, there's one other thing we have to keep in mind.
130
And that's the fact that
131
Next has no way of knowing how many pages we actually have associated to a dynamic route.
132
In order to pre -render all the car IDs, Next needs to know those IDs in advance.
133
And the way we provide that information is by implementing the get static paths function.
134
This function can also request data from an API or database,
135
then its job is to return a paths object that contains an array with every route for this dynamic URL.
136
In this demo, we only have three routes, Tesla, Ford, and Lambo.
137
We map those values to an array of objects, then return them from the function, along with additional options like the fallback behavior.
138
Now if we go visit the app in the browser.
139
we should see a fully rendered web page.
140
It doesn't look any different than a regular React app.
141
However, if you open up the Sources panel in Chrome DevTools, it'll show you the fully rendered HTML before it was touched by JavaScript.
142
Notice how it contains the title and pre -rendered content, which is essential for SEO and sharing content on social media sites.
143
So that's how you implement server -side generation.
144
But another big strategy is server -side rendering.
145
The big difference is that with SSR, the content is generated on a server when requested by the user.
146
This approach is ideal when data changes constantly
147
because it ensures the end user will always get the latest and greatest data from whatever your data source happens to be.
148
However, it's far less efficient because you need to have a server in place to respond to those requests,
149
as opposed to caching everything on a global CDN.
150
Imagine something like an eBay auction where you have millions of listings and those listings are changing all the time.
151
That's probably a good candidate for SSR.
152
In any case, it's very easy to implement a Next.
153
Back in our page file, we'll go ahead and implement another function called getServerSideProps.
154
The only thing that actually changes in our code is the name of the function.
155
We can simply copy the body of the getStaticProps function and paste it into our new function.
156
It does the exact same thing, but does it on every request instead of at build time.
157
Then we can comment out getStaticProps and getStaticPaths because we no longer need those functions.
158
But the real beauty of Next is that we can apply both of these paradigms wherever we want in the application.
159
We're not limited to one or the other.
160
I'm going to go ahead and wrap things up there.
161
If there's anything you want to see in my full
162
Next course, make sure to let me know in the comments.
163
Thanks for watching, and I will see you in the next one.

Télécharger l'application

Tout pour parler couramment

Prononciation IAChaque phrase notée
Phonétique (IPA)Maîtrisez chaque son
VocabulaireEnrichissez votre lexique
Jeu de vocabulaireApprenez en jouant

Même chaîne

FOR YOU

Vidéo recommandée

Vocabulaire et conseils d’expression pour cette leçon

Cette leçon d’expression orale s’appuie sur la vidéo « Next.js in 100 Seconds // Plus Full Beginner's Tutorial ». Les mots qui reviennent le plus souvent : page, component, file, server, route. Cette vidéo contient 163 phrases et 2418 mots à répéter en shadowing. La partie parlée dure 11:49. Le locuteur parle vite, environ 205 mots par minute : attendez-vous à des liaisons et à des sons réduits. Seuls 80 % des mots font partie des 3 000 mots les plus courants en anglais, le vocabulaire est donc exigeant.

Vocabulaire clé de cette vidéo

15 mots de la vidéo à retenir, avec leur prononciation et leur sens :

MotPrononciationSens
render verbe/ˈɹɛn.dɚ/rendre
component nom/kəmˈpoʊ.nənt/composant
server nom/ˈsɝvɚ/serveur
fetch verbe/fɛt͡ʃ/ramener, rapporter
implement verbe/ˈɪmpləmənt/appliquer, exécuter
react verbe/ɹiːˈækt/réagir
directory nom/dɪˈɹɛktəɹi/annuaire
static adjectif/ˈstæt.ɪk/statique
dynamic adjectif/daɪˈnæm.ɪk/dynamique
prop nom/pɹɑp/cale, support
define verbe/dɪˈfaɪn/déterminer
default nom/dɪˈfɔlt/défaut, non-respect
export nom/ˈɛks.pɔɹt/exportation
generate verbe/ˈd͡ʒɛn.ə.ɹeɪt/générer
navigate verbe/ˈnæv.ɪ.ɡeɪt/naviguer

Les verbes à particule que vous entendrez

MotPrononciationSens
go ahead verbe/ˌɡoʊ əˈhɛd/vas-y, allez-y
open up verbeouvrir
point out verbepointer
come up with verbeinventer, imaginer
set up verbe/ˌsɛt ˈʌp/mettre en place, installer
take over verbereprendre

La grammaire de cette vidéo

Les structures que le locuteur utilise le plus, avec les mots exacts de la vidéo :

StructureDans la vidéo
Voix passive be + participe passé — l’accent est mis sur ce qui arrive, pas sur qui le faitis rendered · is not reliably indexed · can be easily cached
Propositions relatives who / which + proposition — une précision sur une personne ou une choseJanuary, which will · file, which is · export, which is
Present perfect have/has + participe passé — une action passée qui compte encore maintenanthas been · I've added · have associated

Prononciation à surveiller

Le locuteur utilise 25 contractions et formes réduites, comme we'll, doesn't, I'm. Prononcez-les sous leur forme courte, telles que vous les entendez.

  • Les sons « sh » et « zh »: cache /kæʃ/, efficient /ɪˈfɪʃənt/, congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/, sheet /ʃit/, shell /ʃɛl/
  • Mots longs — placez bien l’accent: directory /dɪˈɹɛktəɹi/, interactive /ˌɪn.tɚˈæk.tɪv/, congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/, fundamental /ˌfʌn.dəˈmɛn.təl/, navigation /nævɪˈɡeɪʃən/

Les sons difficiles pour les francophones :

  • /h/ — il se souffle, il n’est pas muet: hook /hʊk/, wherever /(h)wɛɹˈɛvɚ/, placeholder /ˈpleɪsˌhoʊldɚ/
  • /tʃ/ et /dʒ/ — à ne pas adoucir en « ch » et « j »: fetch /fɛt͡ʃ/, generate /ˈd͡ʒɛn.ə.ɹeɪt/, module /ˈmɑd͡ʒul/, package /ˈpæk.ɪd͡ʒ/, congratulations /kənˌɡɹæt͡ʃəˈleɪʃ(ə)nz/
  • /r/ anglais — langue recourbée, sans frotter la gorge: render /ˈɹɛn.dɚ/, react /ɹiːˈækt/, directory /dɪˈɹɛktəɹi/, prop /pɹɑp/, browser /ˈbɹaʊ.zəɹ/

Comment s’entraîner avec cette vidéo

  1. Écoutez la vidéo en entier une fois sans parler et notez les mots que vous ne connaissez pas.
  2. Commencez à la vitesse 0,75×, répétez phrase par phrase, puis revenez à la vitesse normale quand cela devient facile.
  3. Enregistrez-vous et comparez avec l’original, en faisant attention à des mots comme render, component, server.

Qu'est-ce que la technique du Shadowing ?

Le Shadowing est une technique d'apprentissage des langues fondée sur la science, développée à l'origine pour la formation des interprètes professionnels. Le principe est simple mais puissant : vous écoutez de l'anglais natif et le répétez immédiatement à voix haute — comme une ombre suivant le locuteur avec un décalage de 1 à 2 secondes. Les recherches montrent une amélioration significative de la précision de la prononciation, de l'intonation, du rythme, des liaisons, de la compréhension orale et de la fluidité.

Technique du shadowing : lire le guide complet étape par étape →