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
67
Other Decks in Programming
See All in Programming
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
340
Family mrubyの進捗
kishima
1
110
信頼性の目標を誰も求めてない
shubox
0
500
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
5.8k
Claude Codeを組織的に動かして月400PRを実現した話
happy_ryo
0
270
Press start. Python's next generation.
willingc
PRO
3
330
高専キャリア LT 発表内容
crysta1221
6
5.6k
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
230
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
200
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
アクセシビリティから考える情報設計
high_g_engineer
0
350
Intent as Code
shoppingjaws
6
740
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Being A Developer After 40
akosma
91
590k
Crafting Experiences
bethany
1
310
Accessibility Awareness
sabderemane
1
210
Building AI with AI
inesmontani
PRO
1
1.2k
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!