-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
497 lines (451 loc) · 15.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>
¿Qué es NextJS? La nueva manera de crear aplicaciones en NextJS
</title>
<link
href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="dist/reveal.css" />
<link rel="stylesheet" href="dist/theme/nextjs.css" id="theme" />
<!-- Theme used for syntax highlighted code -->
<link
rel="stylesheet"
href="plugin/highlight/atom-one-dark.css"
id="highlight-theme"
/>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<a
href="https://nextjs.org/"
target="_blank"
rel="noopener noreferrer"
>
<img
src="img/nextjs.svg"
alt="NextJS logo"
style="
height: 250px;
margin: 0 auto 1rem auto;
background: transparent;
"
class="demo-logo"
/>
</a>
<h3>¿Qué es NextJS?</h3>
<p>
<small>La nueva manera de crear aplicaciones con React</small>
</p>
</section>
<section
data-background-iframe="https://danestves.com/es"
data-background-interactive
></section>
<section>
<section>
<h3>¿Qué es?</h3>
<p>
<small>
NextJS es una framework para React el cual nos brinda la
posibilidad de crear aplicaciones en tres posibles maneras:
Client Side Rendering (CSR), Server Side Rendering (SSR) y
Static Site Generation (SSG)
</small>
</p>
</section>
<section>
<h3>Client Side Rendering (CSR)</h3>
<p>
<small>
Es una solución de render que hace que en un único archivo HTML
se concentre todas las vistas, rutas, lógica y más para la
aplicación. En este caso estamos dejándole todo el trabajo de
render al navegador.
</small>
</p>
<img
src="img/csr.png"
alt="Client Side Rendering"
style="filter: grayscale(1)"
/>
</section>
<section>
<h3>Server Side Rendering (SSR)</h3>
<p>
<small>
Esta solución de render viene desde hace años con PHP, en el que
construimos un HTML y con PHP le mandamos los datos pero no son
accesibles en el navegador. Quiere decir que cuando renderiza la
página trae los datos en tiempo real directamente de nuestro
servidor
</small>
</p>
<img
src="img/ssr.png"
alt="Server Side Rendering"
style="filter: grayscale(1)"
/>
</section>
<section>
<h3>Static Site Generation (SSG)</h3>
<p>
<small>
Se crean páginas HTML a partir de plantillas o componentes y una
fuente de contenido como una base de datos o una REST API.
Normalmente se hace usando archivos de Markdown pero en la
actualidad se puede usar cualquier tipo de archivos siempre y
cuando los datos vengan en formato JSON
</small>
</p>
<img
src="img/ssg.jpg"
alt="Static Site Generation"
style="filter: grayscale(1)"
/>
</section>
</section>
<section>
<h3>¿Qué nos ofrece?</h3>
<div class="mx-auto max-w-xl">
<img
src="img/features.png"
alt="Características de NextJS"
style="margin: 0; max-width: 100%; max-height: 100%"
/>
</div>
</section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>`/pages/index.jsx`</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers>
const Home = () => {
return (
<div>
<h1>Hello Word</h1>
<p>This is my page made with NextJS</p>
</div>
)
}
export default Home
</code></pre>
<p class="text-base">
Así se ve una página en NextJS, no es necesario importar React como
se hace normalmente porque NextJS ya lo hace por nosotros
</p>
</section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>`src/views/index.jsx`</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="1">
import React from "react"
const Home = () => {
return (
<div>
<h1>Hello Word</h1>
<p>This is my page made with NextJS</p>
</div>
)
}
export default Home
</code></pre>
<p class="text-base">
Normalmente en React debemos hacer esto para que el compilador
detecte React en ese archivo
</p>
</section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>
`Client Side Data Fetching`
</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="4-12|14-22">
import React from "react"
const Home = () => {
const [data, setData] = useState(null)
React.useEffect(() => {
fetch("...").then((result) => {
setData(result.data)
}).catch((err) => {
console.error(err)
});
}, [])
return (
<div>
{data ? (
<React.Fragment>
<h1>{data.title}</h1>
<p>{data.description}</p>
</React.Fragment>
) : "Loading..."}
</div>
)
}
export default Home
</code></pre>
</section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>`getServerSideProps`</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="5-10|1-3">
function Page({ data }) {
// Render data...
}
export async function getServerSideProps() {
const res = await fetch(`https://.../data`)
const data = await res.json()
return { props: { data } }
}
export default Page
</code></pre>
</section>
<section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>`getStaticProps`</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="11-20|1-9">
function Blog({ posts }) {
return (
<ul>
{posts.map((post) => (
<li>{post.title}</li>
))}
</ul>
)
}
export async function getStaticProps() {
const res = await fetch('https://.../posts')
const posts = await res.json()
return {
props: {
posts,
},
}
}
export default Blog
</code></pre>
</section>
<section data-auto-animate>
<h2 data-id="code-title" data-markdown>`revalidate`</h2>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="19">
function Blog({ posts }) {
return (
<ul>
{posts.map((post) => (
<li>{post.title}</li>
))}
</ul>
)
}
export async function getStaticProps() {
const res = await fetch('https://.../posts')
const posts = await res.json()
return {
props: {
posts,
},
revalidate: 1200
}
}
export default Blog
</code></pre>
</section>
</section>
<section>
<section data-auto-animate>
<div data-id="code-title" data-markdown>### `getStaticPaths`</div>
<pre
data-id="code-animation"
><code class="hljs javascript" data-trim data-line-numbers>
export async function getStaticPaths() {
return {
paths: [
{ params: { ... } }
],
fallback: true or false
};
}
</code></pre>
</section>
<section data-auto-animate>
<div data-id="code-title" data-markdown>### `paths`</div>
<pre
data-id="code-animation"
><code class="hljs javascript" data-trim data-line-numbers="2-5">
return {
paths: [
{ params: { slug: 'how-to-use-google' } },
{ params: { slug: 'why-i-dont-use-nexjs' } }
],
fallback: true
}
</code></pre>
<div data-markdown class="text-base">
Con esto NextJS generará estáticamente las páginas: <br />
- `https://myblog.com/posts/how-to-use-google` <br />
- `https://myblog.com/posts/why-i-dont-use-nexjs`
</div>
<div data-markdown class="text-base">
al momento del build en una template como `pages/posts/[slug].js`
</div>
</section>
<section data-auto-animate>
<div data-id="code-title" data-markdown>### `fallback`</div>
<pre
data-id="code-animation"
><code class="hljs javascript" data-trim data-line-numbers="6">
return {
paths: [
{ params: { slug: 'how-to-use-google' } },
{ params: { slug: 'why-i-dont-use-nexjs' } }
],
fallback: true
}
</code></pre>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="1"
>
Si `fallback` es `false`, entonces cualquier página que no sea
retornada por `getStaticPaths` resultará en un 404.
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="2"
>
Si `fallback` es `true`, el comportamiento cambia:
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="3"
>
- Las rutas devueltas por `getStaticPaths` se convertirán en
`HTML` en tiempo de compilación mediante `getStaticProps`.
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="4"
>
- Las rutas que no se hayan generado en tiempo de compilación no
darán lugar a una página 404. En su lugar, Next.js servirá una
versión `fallback` de la página en la primera petición a la ruta.
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="5"
>
- En segundo plano, Next.js generará estáticamente el `HTML` y el
`JSON` de la ruta solicitada. Esto incluye la ejecución de
`getStaticProps`.
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="6"
>
- Una vez hecho esto, el navegador recibe el `JSON` de la ruta
generada. Esto se utilizará para renderizar automáticamente la
página con los props requeridos. Desde la perspectiva del usuario,
la página pasará de ser la página de reserva a la página completa.
</div>
<div
data-markdown
class="text-base fragment text-left"
data-fragment-index="7"
>
- Al mismo tiempo, Next.js añade esta ruta a la lista de páginas
pre-renderizadas. Las siguientes peticiones a la misma ruta
servirán la página generada, al igual que otras páginas
pre-renderizadas en el momento de la construcción.
</div>
</section>
</section>
<section data-auto-animate>
<div data-id="code-title" data-markdown>
###### `pages/posts/[slug].js`
</div>
<div data-id="code-title" data-markdown>
###### `getStaticPaths` + `getStaticProps`
</div>
<pre
data-id="code-animation"
><code class="hljs" data-trim data-line-numbers="13-21|23-31|1-11|4-8|10">
import { useRouter } from 'next/router'
function Post({ post }) {
const router = useRouter()
if (router.isFallback) {
return <div>Loading...</div>
}
// Render post...
}
export async function getStaticPaths() {
return {
paths: [
{ params: { slug: 'how-to-use-google' } },
{ params: { slug: 'why-i-dont-use-nexjs' } }
],
fallback: true,
}
}
export async function getStaticProps({ params }) {
const res = await fetch(`https://.../posts/${params.slug}`)
const post = await res.json()
return {
props: { post },
revalidate: 1200,
}
}
export default Post
</code></pre>
</section>
<section>
<h2>¿Qué puedo construir con NextJS?</h2>
<ul>
<li>Blogs</li>
<li>Portafolios</li>
<li>Aplicaciones</li>
<li>Y mucho más</li>
</ul>
</section>
<section
data-background-image="https://i.giphy.com/26FPOogenQv5eOZHO.gif"
></section>
</div>
</div>
<script src="dist/reveal.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/markdown/markdown.js"></script>
<script src="plugin/highlight/highlight.js"></script>
<script>
// More info about initialization & config:
// - https://revealjs.com/initialization/
// - https://revealjs.com/config/
Reveal.initialize({
hash: true,
// Learn about plugins: https://revealjs.com/plugins/
plugins: [RevealMarkdown, RevealHighlight, RevealNotes],
});
</script>
</body>
</html>