-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter2.html
507 lines (408 loc) · 27.9 KB
/
chapter2.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
498
499
500
501
502
503
504
505
506
507
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Learning React - Introducing React</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="icon" type="image/x-icon" href="mc2/images/favicon.ico">
<link rel="stylesheet" href="mc2/styles/reveal.css">
<link rel="stylesheet" href="mc2/styles/theme.css" id="theme">
<link rel="stylesheet" href="mc2/styles/code.css">
<link rel="stylesheet" href="styles/react.css">
</head>
<body>
<div id="pos"></div>
<div class="reveal">
<div class="slides">
<section class="slide chaptertitle">
<div class="slidecontent">
<div class="chapternumber"> chapter 2 of 14 </div>
<h1>Introducing React</h1>
<span>What's the fuss about?</span>
</div>
</section>
<section class="slide sectionlist">
<div class="slidecontent">
<h3>Sections in this chapter</h3>
<ol>
<li><a href="#/2">Expressing the UI</a></li>
<li><a href="#/3">Installing JSX</a></li>
<li><a href="#/4">Updating the UI</a></li>
<li><a href="#/5">React devtools</a></li>
</ol>
</div>
</section>
<section>
<section class="slide sectiontitle">
<div class="slidecontent">
<div class='sectioncount'>Section 1/4</div>
<h3>Expressing the UI</h3>
<p>Dissecting a React component</p>
</div>
</section>
<section class="slide" data-pos="2-1-1">
<span class="pos">2-1-1</span>
<div class="slidecontent"><p>In Handlebars you <strong>write a definition</strong> in <strong>html</strong> which is then <strong>compiled</strong> into a <strong>template function</strong></p>
<p>In React there is <strong>no compilation</strong>. Instead you <strong>work with JS</strong> and <strong>write the template function yourself</strong>!</p>
</div></section>
<section class="slide" data-pos="2-1-2">
<span class="pos">2-1-2</span>
<div class="slidecontent"><p>Here's the mandatory <a href="resources/site/demos/helloworld/index.html" target="_blank">HelloWorld</a> demo!</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> HelloWorld = <span class="hljs-function"><span class="hljs-params">props</span> =></span> <div>Hello world!<span class="xml"><span class="hljs-tag"></<span class="hljs-name">div</span>></span></span>;
</code></pre>
<p>As you can see the <code>HelloWorld</code> <strong>component</strong> is a <strong>plain JavaScript function</strong>, although with some <strong>weird xml syntax</strong> mixed in! That's called <strong>JSX</strong>, short for <strong>JavaScript XML</strong>.</p>
</div></section>
<section class="slide" data-pos="2-1-3">
<span class="pos">2-1-3</span>
<div class="slidecontent"><p>The previous example was a bit boring as it was <strong>completely static</strong>. Here instead is a <a href="resources/site/demos/hellosomeone/index.html" target="_blank">HelloSomeone</a> component which greets whoever you tell it to:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> HelloSomeone = <span class="hljs-function"><span class="hljs-params">props</span> =></span> <div>Hello, {props.who}!<span class="xml"><span class="hljs-tag"></<span class="hljs-name">div</span>></span></span>;
</code></pre>
<p>So, <strong>inside JSX</strong> we use <strong>single braces</strong> to <strong>switch back to JavaScript</strong>.</p>
</div></section>
<section class="slide question" data-pos="2-1-4">
<span class="pos">2-1-4</span>
<div class="slidecontent">
<p>Hang on - how was that better than Handlebars? Wasn't the earlier Handlebars version...</p>
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-name">div</span>></span>Hello, {{who}}!<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
</code></pre>
<p>...much easier to both read and write?</p>
</div></section>
<section class="slide answer" data-pos="2-1-5">
<span class="pos">2-1-5</span>
<div class="slidecontent">
<p>For this simple example, yes. But! Just <strong>regular HTML is rarely enough</strong> to formulate the view.</p>
<p>A competent templating solution needs to <strong>provide more opportunity to express logic</strong> in connection with describing what the output should look like.</p>
</div></section>
<section class="slide" data-pos="2-1-6">
<span class="pos">2-1-6</span>
<div class="slidecontent"><p>Consider for example a view that is supposed to render a bunch of <strong>links to a list of posts</strong>. We need to...</p>
<ul>
<li><strong>repeat</strong> some HTML for every link</li>
<li>or <strong>conditionally</strong> display an apologetic message if there are no posts yet.</li>
</ul>
</div></section>
<section class="slide" data-pos="2-1-7">
<span class="pos">2-1-7</span>
<div class="slidecontent"><p>Here's a <strong>Handlebars solution</strong> to the aforementioned problem:</p>
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"posts"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">h2</span>></span>Posts<span class="hljs-tag"></<span class="hljs-name">h2</span>></span>
{{#if posts}}
{{#each posts}}
<span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"post"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"{{this.url}}"</span>></span>{{this.title}}<span class="hljs-tag"></<span class="hljs-name">a</span>></span>
{{/each}}
{{else}}
<span class="hljs-tag"><<span class="hljs-name">p</span>></span>No posts :(<span class="hljs-tag"></<span class="hljs-name">p</span>></span>
{{/if}}
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
</code></pre>
</div></section>
<section class="slide" data-pos="2-1-8">
<span class="pos">2-1-8</span>
<div class="slidecontent"><p>As you saw, <strong>Handlebars</strong> - like so many other templating solutions - has <strong>augmented HTML</strong> with <strong>additional logic helpers</strong>, to accommodate for the fact that <strong>views often need logic</strong>.</p>
</div></section>
<section class="slide" data-pos="2-1-9">
<span class="pos">2-1-9</span>
<div class="slidecontent"><p>This invariably means that you <strong>have to learn these augmentations</strong>, which are always <strong>solution-specific</strong>. Your knowledge on Handlebars helpers is <strong>useless outside a Handlebars context</strong>.</p>
</div></section>
<section class="slide" data-pos="2-1-10">
<span class="pos">2-1-10</span>
<div class="slidecontent"><p>Here is a <strong>React solution</strong> to the same problem:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> ListOfPosts = <span class="hljs-function"><span class="hljs-params">props</span> =></span> {
<span class="hljs-keyword">let</span> posts = (props.posts || []).map(<span class="hljs-function"><span class="hljs-params">p</span> =></span> (
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"post"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">{p.url}</span>></span>{p.title}<span class="hljs-tag"></<span class="hljs-name">a</span>></span></span>
);
<span class="hljs-keyword">return</span> (
<span class="xml"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"posts"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">h2</span>></span>Posts<span class="hljs-tag"></<span class="hljs-name">h2</span>></span>
{ props.posts.length > 0 ? posts : <span class="hljs-tag"><<span class="hljs-name">p</span>></span>No posts ☹<span class="hljs-tag"></<span class="hljs-name">p</span>></span> }
<span class="hljs-tag"></<span class="hljs-name">div</span>></span></span>
);
};
</code></pre>
</div></section>
<section class="slide" data-pos="2-1-11">
<span class="pos">2-1-11</span>
<div class="slidecontent"><p>Apart from the JSX syntax, everything else in the code is <strong>just pure JavaScript</strong>. Being an actual programming language, it has <strong>no problem with expressing logic</strong>.</p>
</div></section>
<section class="slide" data-pos="2-1-12">
<span class="pos">2-1-12</span>
<div class="slidecontent"><p><strong>HTML</strong> is of course <strong>better</strong> at <strong>expressing markup</strong>, since it is a markup language. This is why Facebook added the <strong>JSX syntax</strong> to JavaScript.</p>
</div></section>
<section class="slide" data-pos="2-1-13">
<span class="pos">2-1-13</span>
<div class="slidecontent"><p>In essence: In a view we need to <strong>describe nested data</strong> (HTML) in connection with <strong>logic</strong>. This gives us two options:</p>
<ol>
<li>Use a <strong>nested data language</strong> with <strong>logic helpers</strong></li>
<li>Use a <strong>logic language</strong> with <strong>nested data helpers</strong></li>
</ol>
</div></section>
<section class="slide" data-pos="2-1-14">
<span class="pos">2-1-14</span>
<div class="slidecontent"><p>Since <strong>logic is much more complex than nested data</strong>, option 2 seems much easier.</p>
<p>Yet, <strong>everyone but React chose option 1</strong>!</p>
</div></section>
</section>
<section>
<section class="slide sectiontitle">
<div class="slidecontent">
<div class='sectioncount'>Section 2/4</div>
<h3>Installing JSX</h3>
<p>Who put the HTML in the JS?</p>
</div>
</section>
<section class="slide" data-pos="2-2-1">
<span class="pos">2-2-1</span>
<div class="slidecontent"><p>Since <strong>JSX isn't</strong> (yet) a <strong>part of the language</strong>, some kind of <strong>transpilation</strong> must occur. </p>
<p><img src="resources/2-2-1-99.svg" alt="dot"></p>
<p>Otherwise the <strong>browser wouldn't know</strong> how to interpret the code. But <strong>where does this happen</strong>?</p>
</div></section>
<section class="slide" data-pos="2-2-2">
<span class="pos">2-2-2</span>
<div class="slidecontent"><p>The absolute <strong>majority of React developers</strong> have a <strong>build step</strong> that doesn't just take care of <strong>JSX</strong>, but also allows the use of <strong>modules</strong> and perhaps <strong>other ES6/ES7 features</strong>.</p>
<p>This isn't unique to React, but true for <strong>JavaScript development in general</strong>.</p>
</div></section>
<section class="slide" data-pos="2-2-3">
<span class="pos">2-2-3</span>
<div class="slidecontent"><p>The <strong>most popular tools</strong> for this are <a href="https://webpack.github.io/" class="link" target="_blank">Webpack</a> and <a href="http://browserify.org/" class="link" target="_blank">Browserify</a>.</p>
<p>They run <strong>JavaScript code on your local machine</strong> using <a href="https://nodejs.org/en/" class="link" target="_blank">Node</a>, which in turn allows you to <strong>download dependencies</strong> using <a href="https://www.npmjs.com/" class="link" target="_blank">npm</a>.</p>
</div></section>
<section class="slide" data-pos="2-2-4">
<span class="pos">2-2-4</span>
<div class="slidecontent"><p>There's a lot <strong>more to be said about the build step</strong>, but we'll leave it for now as we'll use an <strong>in-browser solution</strong> to avoid complexity.</p>
</div></section>
<section class="slide" data-pos="2-2-5">
<span class="pos">2-2-5</span>
<div class="slidecontent"><p>What we'll do is use a browser version of <a href="https://babeljs.io/" class="link" target="_blank">Babel</a>, a library that can do all sorts of <strong>transformations on JavaScript code</strong>, including handling JSX.</p>
</div></section>
<section class="slide" data-pos="2-2-6">
<span class="pos">2-2-6</span>
<div class="slidecontent"><p>Our setup is very easy - we <strong>include babel as a script tag</strong> along with everything else we need...</p>
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-name">head</span>></span>
<span class="hljs-tag"><<span class="hljs-name">title</span>></span>Playing with React<span class="hljs-tag"></<span class="hljs-name">title</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"lib/react.min.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">scripτ</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"lib/react-dom.min.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">scripτ</span>></span>
<span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"lib/babel.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">scripτ</span>></span>
<span class="hljs-tag"></<span class="hljs-name">head</span>></span>
</code></pre>
</div></section>
<section class="slide" data-pos="2-2-7">
<span class="pos">2-2-7</span>
<div class="slidecontent"><p>...and then we put our <strong>code</strong> in <strong>script tags</strong> with <strong>type</strong> set to <strong><code>text/babel</code></strong>:</p>
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/babel"</span>></span>
let MyReactComponent = props => (
<span class="hljs-tag"><<span class="hljs-name">div</span>></span>I can use <span class="hljs-tag"><<span class="hljs-name">strong</span>></span>JSX<span class="hljs-tag"></<span class="hljs-name">strong</span>></span>!<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
);
<span class="hljs-tag"></<span class="hljs-name">scripτ</span>></span>
</code></pre>
<p>Babel will <strong>notice the type</strong> and <strong>perform the conversion</strong> to regular JS when the <strong>document loads</strong>.</p>
</div></section>
<section class="slide" data-pos="2-2-8">
<span class="pos">2-2-8</span>
<div class="slidecontent"><p>Note however that this solution is <strong>only for toying and demoing</strong>!</p>
<p>In a <strong>production environment</strong> you should <strong>precompile</strong> in a <strong>build step</strong> as previously discussed.</p>
</div></section>
<section class="slide question" data-pos="2-2-9">
<span class="pos">2-2-9</span>
<div class="slidecontent">
<p>Whether we do it in a build step or in the browser - why isn't <strong>converting JSX</strong> a <strong>part of React</strong>?</p>
</div></section>
<section class="slide answer" data-pos="2-2-10">
<span class="pos">2-2-10</span>
<div class="slidecontent">
<p>Two main reasons;</p>
<ul>
<li>As shown <strong>JSX isn't mandatory</strong>, you can use React just fine without it.</li>
<li>Also, <strong>JSX has uses outside of React</strong>. It <strong>isn't a part of React</strong>, but a convenient way to <strong>express nested data</strong>.</li>
</ul>
</div></section>
<section class="slide" data-pos="2-2-11">
<span class="pos">2-2-11</span>
<div class="slidecontent"><p>As a <strong>non-React example</strong>: here's JSX being used in <a href="http://cycle.js.org/" class="link" target="_blank">CycleJS</a> code:</p>
<pre><code class="lang-javascript">/** @jsx hJSX */ // <-- this points JSX to use hJSX instead
import {hJSX} from '@cycle/dom';
function main(drivers) {
return {
DOM: Observable.timer(0, 1000)
.map(i => <div>Seconds elapsed: {i}</div>)
};
}
</code></pre>
</div></section>
</section>
<section>
<section class="slide sectiontitle">
<div class="slidecontent">
<div class='sectioncount'>Section 3/4</div>
<h3>Updating the UI</h3>
<p>acting on changes</p>
</div>
</section>
<section class="slide" data-pos="2-3-1">
<span class="pos">2-3-1</span>
<div class="slidecontent"><p>Let's zoom back out for a bit and consider the problem of <strong>updating our UI</strong> whenever <strong>data changes</strong>.</p>
<p>Handlebars doesn't solve this problem at all, it just provides the <strong>initial DOM</strong>. In a dynamic app we need <strong>additional functionality</strong> to <strong>update</strong> the UI when something happens.</p>
</div></section>
<section class="slide" data-pos="2-3-2">
<span class="pos">2-3-2</span>
<div class="slidecontent"><p>React instead takes a super-simple, brute force approach; it <strong>rerenders everything on every data update</strong>, using the <strong>same function</strong> for the <strong>initial render</strong> and every <strong>subsequent update</strong>.</p>
</div></section>
<section class="slide question" data-pos="2-3-3">
<span class="pos">2-3-3</span>
<div class="slidecontent">
<p>Fine, <strong>rerendering everything on every update</strong> makes life easier for us developers, but surely that must have a huge <strong>performance penalty</strong>, lead to <strong>loss of scroll position</strong> and lots of other headaches for the user?</p>
</div></section>
<section class="slide answer" data-pos="2-3-4">
<span class="pos">2-3-4</span>
<div class="slidecontent">
<p>Nope! And here's why. We actually lied before - a <strong>React component</strong> doesn't output DOM, but <strong>virtual DOM</strong>.</p>
<p><img src="resources/2-3-4-121.svg" alt="dot"></p>
</div></section>
<section class="slide" data-pos="2-3-5">
<span class="pos">2-3-5</span>
<div class="slidecontent"><p>The <strong>virtual DOM</strong> is simply a <strong>JavaScript representation</strong> of a DOM structure. For example, this HTML...</p>
<pre><code class="lang-html"><span class="hljs-tag"><<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"excerpt"</span>></span>
<span class="hljs-tag"><<span class="hljs-name">h2</span>></span>Chapter 1<span class="hljs-tag"></<span class="hljs-name">h2</span>></span>
<span class="hljs-tag"><<span class="hljs-name">p</span>></span>When MacGyver learned to fly<span class="hljs-tag"></<span class="hljs-name">p</span>></span>
<span class="hljs-tag"></<span class="hljs-name">div</span>></span>
</code></pre>
</div></section>
<section class="slide" data-pos="2-3-6">
<span class="pos">2-3-6</span>
<div class="slidecontent"><p>...could be <strong>represented in JS</strong> through something like this:</p>
<pre><code>let virtualDOM = {
<span class="hljs-symbol"> type:</span> <span class="hljs-string">"div"</span>,
<span class="hljs-symbol"> attributes:</span> {<span class="hljs-string">"class"</span>:<span class="hljs-string">"excerpt"</span>},
<span class="hljs-symbol"> children:</span> [{
<span class="hljs-symbol"> type:</span> <span class="hljs-string">"h2"</span>,
<span class="hljs-symbol"> children:</span> [<span class="hljs-string">"Chapter 1"</span>]
},{
<span class="hljs-symbol"> type:</span> <span class="hljs-string">"p"</span>,
<span class="hljs-symbol"> children:</span> [<span class="hljs-string">"When MacGyver learned to fly"</span>]
}]
};
</code></pre></div></section>
<section class="slide" data-pos="2-3-7">
<span class="pos">2-3-7</span>
<div class="slidecontent"><p>To see what <strong>virtual DOM actually looks like</strong>, check out the <a href="resources/site/demos/virtualdom/index.html" target="_blank">VirtualDOM</a> demo!</p>
</div></section>
<section class="slide" data-pos="2-3-8">
<span class="pos">2-3-8</span>
<div class="slidecontent"><p>The point of the <strong>virtual DOM</strong> is that it <strong>allows React to compare new output with the previous output</strong>, and figure out what changes needs to be made to the actual DOM.</p>
<p><strong>Only those changes</strong> are actually made, so the <strong>complete rerender is just conceptual</strong>.</p>
</div></section>
<section class="slide" data-pos="2-3-9">
<span class="pos">2-3-9</span>
<div class="slidecontent"><p>So here is what <strong>actually happens</strong> when the props of a component updates:</p>
<p><img src="resources/2-3-9-77.svg" alt="dot"></p>
</div></section>
<section class="slide" data-pos="2-3-10">
<span class="pos">2-3-10</span>
<div class="slidecontent"><p>This seemingly simple idea is one of the <strong>biggest advantages of React</strong>, as it <strong>removes lots of complexity</strong> and makes <strong>components easy to reason about</strong>.</p>
</div></section>
<section class="slide" data-pos="2-3-11">
<span class="pos">2-3-11</span>
<div class="slidecontent"><p>Perhaps you've heard of <strong>React Fiber</strong>? That was a <strong>complete rewrite of the diffing engine</strong> for React v16, resulting in <strong>faster diffing and rendering</strong>.</p>
</div></section>
<section class="slide" data-pos="2-3-12">
<span class="pos">2-3-12</span>
<div class="slidecontent"><p>You don't need to know more than that since it is <strong>backwards compatible</strong>, but if you're interested the <a href="https://github.com/acdlite/react-fiber-architecture">detailed explanation</a> of the rewrite is rather fascinating.</p>
</div></section>
</section>
<section>
<section class="slide sectiontitle">
<div class="slidecontent">
<div class='sectioncount'>Section 4/4</div>
<h3>React devtools</h3>
<p>The component petri dish</p>
</div>
</section>
<section class="slide" data-pos="2-4-1">
<span class="pos">2-4-1</span>
<div class="slidecontent"><p>So, hopefully you <strong>remember</strong> the <a href="resources/site/demos/nestedcomponents/index.html" target="_blank">Nested components</a> from a couple sections seconds back? If we open the demo and check <strong>webkit inspector</strong> we'd see something like this:</p>
<p><img src="resources/images/react-devtools-without.png" alt="webkit inspector"></p>
</div></section>
<section class="slide" data-pos="2-4-2">
<span class="pos">2-4-2</span>
<div class="slidecontent"><p>That is <strong>not super useful</strong>, as there is <strong>no way of telling what output comes from what component</strong>.</p>
<p>As React developers it is very convenient to <strong>think in components</strong>, so not being able to do that in the debugger is <strong>very detrimental</strong>!</p>
</div></section>
<section class="slide" data-pos="2-4-3">
<span class="pos">2-4-3</span>
<div class="slidecontent"><p>Enter <strong>React devtools</strong>, a <strong>plugin</strong> to <strong>Chrome</strong> or <strong>Firefox</strong>. It provide a <strong>React tab</strong>, which gives the following view instead:</p>
<p><img src="resources/images/react-devtools-with.png" alt="webkit inspector"></p>
<p>Now we can <strong>easily distinguish between the components</strong>!</p>
</div></section>
<section class="slide" data-pos="2-4-4">
<span class="pos">2-4-4</span>
<div class="slidecontent"><p>It can also <strong>show component details</strong> such as <strong>what props were passed</strong>. Below we show this for the <a href="resources/site/demos/hellosomeone/index.html" target="_blank">HelloSomeone</a> demo:</p>
<p><img src="resources/images/react-devtools-details.png" alt="webkit inspector"></p>
</div></section>
<section class="slide" data-pos="2-4-5">
<span class="pos">2-4-5</span>
<div class="slidecontent"><p>For more details, check the <a href="https://github.com/facebook/react-devtools" class="link" target="_blank">React Devtools</a> homepage.</p>
<p>The devtools also do <strong>a lot more</strong>, such as showing <strong>state</strong> and <strong>context</strong>. But you don't know about any of that yet, so, never mind!</p>
</div></section>
</section>
</div>
</div>
<script type="text/javascript">
var basehref = window.location.href.replace(/chapter\d.*?$/,'')
document.addEventListener("keydown", function(e) {
var code = e.which || e.keyCode;
if (code === 13) {
window.location.href = basehref+"index.html?from=1";
} else if (code >= 49 && code <= 4 + 48) {
window.location.hash = "#/" + (code-48+1+0);
}
if (2 < 14) {
if (code === 99 || e.key === 'c') { // the letter C for next Chapter
window.location.href = basehref+"chapter3.html"
}
}
});
</script>
<script src="mc2/scripts/head.js" type="text/javascript"></script>
<script src="mc2/scripts/reveal.js" type="text/javascript"></script>
<script src="mc2/scripts/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
showNotes: false,
transition: 'slide',
dependencies: [
{ src: 'mc2/scripts/plugin/notes/notes.js', async: true }
]
});
window.onload = function() {
var links = document.querySelectorAll("a.link");
for(var i = 0; i < links.length; i++){
var link = links[i];
link.innerHTML = link.innerHTML.replace(/ /g,' ')
}
var posElem = document.getElementById('pos')
function updateReference() {
setTimeout(function() {
var currentpos = document.querySelector('section.present[data-pos]')
if (currentpos) {
posElem.innerHTML = currentpos.getAttribute('data-pos')
} else {
posElem.innerHTML = ''
}
if (document.querySelector('.present.chaptertitle')) {
document.body.classList.add('atchaptertitle');
} else {
document.body.classList.remove('atchaptertitle');
}
}, 10);
}
window.addEventListener("hashchange",updateReference);
updateReference();
};
</script>
</body>
</html>