Co možná nevíte o React Dev Tools

A presentation at Letní ReactGirls & Outreach meetup in August 2023 in Prague, Czechia by Jakub Beneš

Slide 1

Slide 1

Co možná nevíte o React Dev Tools

Slide 2

Slide 2

Jakub Beneš Software Engineer @ Outreach • jukben.codes • github.com/jukben

Slide 3

Slide 3

Agenda 1. (Ne)zábávná teorie 2. Live demo

Slide 4

Slide 4

Čenglish

Slide 5

Slide 5

Bůh dal lidem kód, ďáběl debugger. — ChatGPT 3.5

Slide 6

Slide 6

Slide 7

Slide 7

function MyButton() { return <button>I’m a button</button>; } debugger;

Slide 8

Slide 8

efektivní debugování = profit

Slide 9

Slide 9

function somethingCrazy() { let result = “”; for (let i = 0; i < 5; i++) { if (i === 0 || i === 1) { for (let j = 0; j < 2; j++) { console.log(“tady jsem”); result += i === 1 ? “e” : “r”; } } else if (i === 2) { result += “a”; } else if (i === 3) { result += “c”; } else if (i === 4) { result += “t”; } } return result; }

Slide 10

Slide 10

Někdy je třeba trochu tězkotonážnější technika

Slide 11

Slide 11

Slide 12

Slide 12

Co pro to potřebujeme? • Bežet aplikaci v Dev mode • Defaultní podpora v Create React App, Next.js,… • ESBuild (jsxDev) • Babel (@babel/preset-react) !

Slide 13

Slide 13

React Dev Tools

Slide 14

Slide 14

Trochu React teorie

Slide 15

Slide 15

Úvod do JSX function App() { return <h1>Hello World</h1>; }

Slide 16

Slide 16

import { jsxDev as _jsxDev } from “react/jsx-runtime”; function App() { return _jsxDev( “button”, { children: “I’m a button” }, void 0, false, { fileName: _jsxFileName, lineNumber: 1, columnNumber: 1, }, this ); } https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html

Slide 17

Slide 17

Render a Commit

Slide 18

Slide 18

https://react.dev/learn/render-and-commit

Slide 19

Slide 19

• Triggering a render (delivering the guest’s order to the kitchen) • It’s the component’s initial render. • The component’s (or one of its ancestors’) state has been updated. Re-renders when state updates

Slide 20

Slide 20

• Rendering the component (preparing the order in the kitchen) • On initial render, React will call the root component. • For subsequent renders, React will call the function component whose state update triggered the render.

Slide 21

Slide 21

• Committing to the DOM (placing the order on the table) • For the initial render, React will use the appendChild() DOM API to put all the DOM nodes it has created on screen. • For re-renders, React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.

Slide 22

Slide 22

Slide 23

Slide 23

(React) Dev Tools to nekončí

Slide 24

Slide 24

Díky! Q&A

Slide 25

Slide 25

Resources • React Developer Tools • Chrome DevTools • LocatorJS • Create React App • https://react.dev/learn/render-and-commit • https://react.dev/learn/react-developer-tools • https://github.com/jukben/todo-react