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
66
Other Decks in Programming
See All in Programming
Contextとはなにか
chiroruxx
1
390
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
840
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
110
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
350
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
160
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
360
AI 輔助遺留系統現代化的經驗分享
jame2408
1
1.2k
Vite+ Unified Toolchain for the Web
naokihaba
0
740
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
310
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.3k
フィードバックで育てるAI開発
kotaminato
1
110
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
340
ラッコキーワード サービス紹介資料
rakko
1
3.9M
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
500
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
The Limits of Empathy - UXLibs8
cassininazir
1
450
Why Our Code Smells
bkeepers
PRO
340
58k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
410
Building AI with AI
inesmontani
PRO
1
1.1k
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!