Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Construindo interfaces componentizadas com React
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sérgio Rafael Siqueira
May 17, 2015
Programming
290
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
170
Startup's world for devs
sergiors
0
65
Other Decks in Programming
See All in Programming
スマートグラスで並列バイブコーディング
hyshu
0
130
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
220
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
250
Webフレームワークの ベンチマークについて
yusukebe
0
160
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
2
620
Creating Composable Callables in Contemporary C++
rollbear
0
110
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
190
Claspは野良GASの夢をみるか
takter00
0
190
OSもどきOS
arkw
0
560
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.7k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
190
Featured
See All Featured
Balancing Empowerment & Direction
lara
6
1.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
YesSQL, Process and Tooling at Scale
rocio
174
15k
New Earth Scene 8
popppiees
3
2.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
320
30 Presentation Tips
portentint
PRO
1
320
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
ラッコキーワード サービス紹介資料
rakko
1
3.6M
Design in an AI World
tapps
1
240
Unsuck your backbone
ammeep
672
58k
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!