Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Construindo interfaces componentizadas com React
Search
Sérgio Rafael Siqueira
May 17, 2015
Programming
300
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Construindo interfaces componentizadas com React
Sérgio Rafael Siqueira
May 17, 2015
More Decks by Sérgio Rafael Siqueira
See All by Sérgio Rafael Siqueira
PHP: Uma Jornada Inesperada
sergiors
0
180
Startup's world for devs
sergiors
0
69
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
230
What We Talk About When We Talk About XP
m_seki
2
670
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.9k
Are APIs Still Relevant in the AI Era?
soyuka
0
290
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
120
Security issues being discussed on Web Platforms
petamoriken
0
1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
0
110
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
250
速習iPhone Duo対応
yuukiw00w
1
710
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.7k
Java 27新機能 / Java 27 new features
kishida
2
150
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
How to build a perfect <img>
jonoalderson
1
6k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
480
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
340
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
700
Prompt Engineering for Job Search
mfonobong
0
460
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
It's Worth the Effort
3n
188
29k
Transcript
Construindo interfaces componentizadas com
CTO e Co-fundador da INBEP, startup com foco em educação.
Sérgio Rafael Siqueira github.com/sergiors sergiorsiqueira.com
[email protected]
React é uma library com foco em interface do usuário
Quem usa
Library Framework
O que é interface do usuário?
• Model • Collection
“ É tudo que o usuário pode interagir
{{ mustache }}
<script id="entry-template" type="text/x-handlebars-template"> <p> {{#if liked}} You like this. Click
to toggle. {{else}} You haven't liked this. Click to toggle. {{/if}} </p> </script>
{{ mustache }} <p> {{#liked}} You like this. Click to
toggle. {{^liked}} You haven't liked this. Click to toggle. {{/liked}} </p>
Template + Javascript = Interface
None
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
false } }, handleClick: function() { this.setState({ liked: !this.state.liked }); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return React.DOM.p({onClick: this.handleClick}, 'You '+text+' this.'); } });
http://facebook.github.io/react/docs/component-specs.html#component-specifications { getDefaultProps: function() {}, propTypes: function() {}, mixins: function()
{}, // ... }
“ Legal cara, mas a marcação do Template Engine parece
mais fácil…
JSX
var LikeButton = React.createClass({ getInitialState: function() { return {liked: false}
}, handleClick: function() { this.setState({liked: !this.state.liked}); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return ( <div onClick={this.handleClick}> You {text} this. Click to toggle. </div> ); } });
JSX on the fly <script src="node_modules/react/dist/JSXTransformer.js"></script> <script src=“like-button.js" type="text/jsx"></script>
Task runner
E se já tenho dados em uma camada de persistência?
var LikeButton = React.createClass({ getInitialState: function() { return { liked:
this.props.liked || false } }, componentWillMount: function() { Backbone.Events.on('change:anywhere', function(data) { this.setState({ liked: data.liked }); }.bind(this)); }, handleClick: function() { this.setState({liked: !this.state.liked}); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return ( <div onClick={this.handleClick}>
Métodos de ciclo de vida
Mounting Updating componentWillMount componentDidMount componentWillReceiveProps shouldComponentUpdate componentWillUpdate componentDidUpdate Unmounting componentWillUnmount
http://facebook.github.io/react/docs/component-specs.html#mounting-componentwillmount
var LikeButton = React.createClass({ getInitialState: function() { return {liked: false}
}, componentWillMount: function() { Backbone.Events.on('change:anywhere', function(data) { this.setState({ liked: data.liked }); }.bind(this)); }, handleClick: function() { this.setState({liked: !this.state.liked}); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return ( <div onClick={this.handleClick}> You '+text+' this. Click to toggle. </div>
Chamado imediatamente antes do render inicial. componentWillMount
var LikeButton = React.createClass({ getInitialState: function() { return {liked: false}
}, componentDidMount: function() { $.ajax('example.php') .done(function(res) { this.setState({ liked: res.liked }); }.bind(this)); }, handleClick: function() { this.setState({liked: !this.state.liked}); }, render: function () { var text = this.state.liked ? 'like' : 'haven\'t liked'; return ( <div onClick={this.handleClick}> You '+text+' this. Click to toggle.
componentDidMount Chamado imediatamente após o render inicial. A DOM já
esta pronta! Ideal para trabalhar com biblioteca de terceiros que precisam do objeto na DOM.
Performance
Event Delegation
<div id="um"> <div id="dois"> <div id="tres"></div> </div> </div>
http://loopinfinito.com.br/2013/05/14/entendendo-captura-e-propagacao-de-eventos/ .0 -> #um .0.0 -> #dois .0.0.0 -> #tres
None
Virtual DOM
Por que mutação é ruim
None
None
computa a diferença aplica a mudança cria/altera
Dúvidas? discussões apenas apenas no bar!