Upgrade to PRO for Only $50/YearโLimited-Time Offer! ๐ฅ
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
React JS intro
Search
Gabriele Petronella
September 30, 2015
Programming
3
400
React JSย intro
A lightweight introduction to React JS in the context of web applications
Gabriele Petronella
September 30, 2015
Tweet
Share
More Decks by Gabriele Petronella
See All by Gabriele Petronella
Design System Adventures in React - ReactJS Day 2024
gabro
0
120
Design System Adventures in React
gabro
1
110
Casting Metals
gabro
0
370
Functional Programming in front-end applications
gabro
1
230
Functional Programming in Front-end Applications
gabro
3
190
How to get away with Functional Programming in front-end applications
gabro
3
1.5k
Bridging the tooling gap with Scala.js
gabro
0
290
Monad Transformers Down to Earth
gabro
2
2.7k
Move fast and fix things
gabro
0
350
Other Decks in Programming
See All in Programming
Grafana๏ผๅปบ็ซ็ณป็ตฑๅ จ็ฅ่ฆ่ง็ๆทๅพ
blueswen
0
140
Claude CodeใฎใCompacting Conversationใใไฝๆ50%ๆธ๏ผ CLAUDE.md + 8 Skills ใงๆใใณใณใใญในใ็ฎก็่ก
kmurahama
1
630
ใฏใฉใฆใใซไพๅญใใชใS3ใไฝฟใฃใ้็บ่ก
simesaba80
0
150
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
120
ๅฎใฏๆญดๅฒ็ใชใขใใใใผใใ ใจๆใ AWS Interconnect - multicloud
maroon1st
0
250
Vibe codingใงใใใใใฎ่จ่ชใจ้็บๆๆณ
uyuki234
0
110
20251212 AI ๆไปฃ็ Legacy Code ็ๆ่ก 2025 WebConf
mouson
0
210
TinkerbellใใๅญฆใถใPodใง DHCPใใชใในใณใใๆๆณ
tomokon
0
140
AIๅๆใฆใ่ใใiOSใขใใใชใฎใขใฟใใใคในใ่จญ่จ
yuukiw00w
0
180
์๋๋ก์ด๋ 9๋ ์ฐจ ๊ฐ๋ฐ์, ํ๋ก ํธ์๋ ์ฃผ๋์ด๋ก ์ปค๋ฆฌ์ด ๋ฆฌ์ ํ๊ธฐ
maryang
1
130
AIใณใผใใฃใณใฐใจใผใธใงใณใ๏ผGemini๏ผ
kondai24
0
270
C-Shared Buildใง็ช็ ดใใAI Agent ใใใฏใในใใฎๅฃ
po3rin
0
410
Featured
See All Featured
We Are The Robots
honzajavorek
0
120
The Spectacular Lies of Maps
axbom
PRO
1
400
ไธ็ใฎไบบๆฐใขใใช100ๅใๅๆใใฆ่ฆใใใใคใฆใฉใผใซ่จญ่จใฎๅฟๅพ
akihiro_kokubo
PRO
65
35k
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
110
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
170
Docker and Python
trallard
47
3.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Design and Strategy: How to Deal with People Who Donโt "Get" Design
morganepeng
132
19k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
310
Highjacked: Video Game Concept Design
rkendrick25
PRO
0
240
Transcript
AN INTRODUCTION TO REACTJS GABRIELE PETRONELLA SOFTWARE ENGINEER @ BUILDO
TWITTER: @GABRO27 / @BUILDOHQ
[email protected]
None
HTML
HTML <!DOCTYPE html> <html> <head> <title>This is a title</title> </head>
<body> <p>Hello world!</p> </body> </html>
I just had to take the hypertext idea and connect
it to the TCP and DNS ideas and โ ta- da!โ the World Wide Web โ Tim Berners Lee
THE WEB, IN THE 90S โโโโโโโโโโโโโ ---------- โ โ gimme
dat page โ โ----------------------> โ browser โ server โ โ <html>...</html> โ โ<---------------------- โโโโโโโโโโโโโ ----------
None
<a href="/somewhere-fun">LINK!</a>
โโโโโโโโโโโโโ โ โ gimme dat page โ
โ----------------------> โ โ โ โ <html>...</html> โ โ<---------------------- โ browser โ ... server โ โ โ โ do dat thing โ โ----------------------> โ โ โ โ <html>...</html> โ โ<---------------------- โ โ โโโโโโโโโโโโโ
None
ADDING AN ELEMENT TO A CART <ul> <ul> <li>An apple</li>
<li>An apple</li> <li>A horse</li> ---> <li>A horse</li> </ul> <li>A dragon</li> </ul>
None
JAVASCRIPT (1995)
None
ADDING AN ELEMENT TO A CART var ul = document.getElementById("cart");
var li = document.createElement("li"); li.appendChild(document.createTextNode("Four")); ul.appendChild(li);
โโโโโโโโโโโโโ โ โ gimme dat page โ
โ----------------------> โ โ <html>...</html> โ browser โ<---------------------- โ โ script.js โ โ<---------------------- server โ โโโโโโโ โโโโโโโโโโโโโ ! โฒ ! <html>...</html>! !add item ! ! "########$ ! ! ! ! ! script !----- ! ! %########&
None
SO YOU SAY WE CAN CREATE HTML ELEMENTS...
SPA SINGLE-PAGE APPLICATIONS
โโโโโโโโโโโโโ โ โ gimme dat page โ
โ----------------------> โ โ <html>...</html> โ browser โ<---------------------- โ โ app.js โ โ<---------------------- โ โ โโโโโโ โโโโโโโโโโโโโ ! โฒ ! server <html>...</html>! !do stuff ! ! "##########$ ! ! !<----- ! ! gimme data ! app.js !----------------------> ! ! ! ! { data: "blah", ... } ! !<---------------------- %##########&
THE USUAL SUSPECTS
SOUNDS GREAT BUT...
COMPLEXITY!
MUTABLE STATE
OVER THE LAST 25 YEARS WE'VE SEEN...
FLUSH THE PAGE AT EVERY CHANGE VS COMPUTE THE CHANGES
LOCALLY
HERE'S HOW THE PAGE SHOULD LOOK LIKE VS HERE'S HOW
TO MAKE IT
IN OTHER WORDS...
DECLARATIVE VS IMPERATIVE
AND POTENTIALLY...
DEVELOPER EXPERIENCE VS USER EXPERIENCE
MEET REACT
DX + UX = REACT
DECLARATIVE APPROACH CONCEPTUALLY RE-RENDERING EVERYTHING EVERYTIME
IMPERATIVE EXPERIENCE MUTATION HAPPENS BEHIND THE SCENE
MVC
IT'S ALL ABOUT REUSABLE COMPONENTS
None
OUR FIRST COMPONENT const Hello = React.createClass({ render() { return
<div>Hello!</div>; } });
WAIT! HTML INSIDE JAVASCRIPT?!
YES, ALMOST...
JSX <div>Hello</div> gets translated to React.createElement("div", null, "Hello");
Details aside, there's no separation between templates and logic
SEPARATE CONCERNS NOT TECHNOLOGIES
ONLY TWO THINGS CAN AFFECT A COMPONENT > props !
> state "
PROPS ! A generalization over HTML attributes <button className='button inactive'>Click</button>
gets translated to React.createElement( "button", { className: 'button inactive' }, // <--- props "Click" );
OUR FIRST COMPONENT ACCEPTING PROPS const Greeter = React.createClass({ render()
{ return <div>Hello {this.props.name}!</div>; } ^ }); | just a javascript variable
AND THEN USE IT LIKE <Greeter name='Gabriele' /> ^ |_____________
passing a prop
CAN THIS BE EFFICIENT?
YOU WRITE render() { return ( <div> <span>Hello {this.props.userName}!</span> </div>
); }
REACT COMPUTES renderA: <div><span>Hello Gabriele!</span></div> renderB: <div><span>Hello Irina!</span></div> => [replaceAttribute
textContent 'Hello Irina'] ^ | | a state mutation, i.e. the horrible thing you want to avoid writing by hand
STATE ! A component can have an internal state AVOID
WHEN YOU CAN!
OUR FIRST STATEFUL COMPONENT !
const Counter = React.createClass({ getInitialState() { return { count: 0
}; }, increaseCount() { this.setState({ count: this.state.count + 1 }); }, ^ |_______________ triggers a re-render render() { return ( <div> <span>{this.state.count}</span> <button onClick={this.increaseCount}>Increase</button> </div> ); } });
THAT'S IT
REACT RECAP Everything is a component Components accept props Components
can have a state !
DEMO
THANKS
<Speaker questions={?} />