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
[React Meetup Campinas 2017] Porque React criou...
Search
Talysson de Oliveira Cassiano
May 10, 2017
Programming
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
[React Meetup Campinas 2017] Porque React criou uma revolução - e você devia saber disso
Talysson de Oliveira Cassiano
May 10, 2017
More Decks by Talysson de Oliveira Cassiano
See All by Talysson de Oliveira Cassiano
[DDD Europe 2026] So you want to be a DDD practitioner
talyssonoc
0
96
[Tropical on Rails 2026] Privacy on Rails
talyssonoc
1
120
[Nerdearla Argentina 2025] LLMs as domain experts
talyssonoc
0
66
[TDC SP 2025] Então você quer ser um praticante de DDD
talyssonoc
0
84
[DDD Brasil] Então você quer ser um praticante de DDD
talyssonoc
0
59
[Rails World 2025 Lighting Talks] Where is it?! - Avoiding the XY Problem
talyssonoc
0
69
[TDC Floripa 2025] Abordagens funcionais efetivas em TypeScript com Effect-TS
talyssonoc
0
130
[TDC Floripa 2025] Modelagem de domínios como construção de teorias
talyssonoc
0
110
[Encontro GURU-SP e ELUG] Ruby on Fails - Tratamento de erros de maneira efetiva e com convenções do Rails
talyssonoc
0
70
Other Decks in Programming
See All in Programming
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
250
信頼性の目標を誰も求めてない
shubox
0
480
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
100
[DroidKaigi 26] How We Moved from Android Studio to Slack
thisaay
0
190
不幸な GC
chencmd
0
870
What We Talk About When We Talk About XP
m_seki
2
320
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
Flow は今どうなっているか
mizdra
PRO
0
890
【デモ】Kiroで体験する仕様駆動開発|設計からコーディングまでAIと進める開発フロー
cmkudo
0
560
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
140
Deep dive into the select statement (GopherCon UK)
jespino
0
170
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
Featured
See All Featured
Writing Fast Ruby
sferik
630
63k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Designing Experiences People Love
moore
143
24k
Mobile First: as difficult as doing things right
swwweet
225
10k
Designing for Performance
lara
611
70k
What's in a price? How to price your products and services
michaelherold
247
13k
My Coaching Mixtape
mlcsv
0
300
Side Projects
sachag
455
43k
So, you think you're a good person
axbom
PRO
2
2.1k
Unsuck your backbone
ammeep
672
58k
Test your architecture with Archunit
thirion
2
2.4k
Transcript
Porquê o React criou uma revolução E você devia saber
disso
Talysson @talyssonoc talyssonoc.github.io Front-end Codeminer42
React?!
“ Uma biblioteca JavaScript para construir interfaces de usuário. -
React, Documentação do
C M V
C M
¡Viva la revolución reacción!
Componentização
class GreetMessage extends React.Component { render() { return ( <div>
Hey, { this.props.name }. </div> ); } } ReactDOM.render( <GreetMessage name="Meetup attendant"/>, document.querySelector('#app') );
Antes // app.js angular.module('meetup', []) .controller('GreetCtrl', function($scope) { $scope.name =
'Meetup attendant'; }); // app.html <div ng-controller="GreetCtrl"> Hey, {{ name }}. </div> // app.js App.GreetMsgView = Ember.View.extend({ templateName: 'greet_msg' }); App.HomePageView = Ember.View.extend({ templateName: 'home_page', name: 'Meetup speaker' }); // home_page template {{#view 'greet_msg'}} // greet_msg template Hello, {{name}} Angular < 1.5 Ember 1.x
Depois // app.js angular.module('meetup', []) .controller('GreetCtrl', function($scope) { $scope.name =
'Meetup attendant'; }) .component('greetMsg', { template: 'Hey, {{ $ctrl.name }}.', bindings: { name: '=' } }); // app.html <div ng-controller="GreetCtrl"> <greet-msg name="name"></greet-msg> </div> // app.js App.GreetMsgComponent = Ember.Component.extend({ templateName: 'greet_msg' }); App.HomePageView = Ember.View.extend({ templateName: 'home_page', name: 'Meetup speaker' }); // home_page template {{greet-msg name=name}} // greet_msg template Hello, {{name}} Angular 1.5+ Ember 2.x
Composição
class GreetMessage extends React.Component { render() { return ( <div>
Hey, { this.props.name }. </div> ); } } class HomePage extends React.Component { render() { return ( <div> <h1>Welcome</h1> <GreetMessage name="Meetup attendant"/> </div> ); } } ReactDOM.render( <HomePage />, document.querySelector('#app') );
Antes Angular 1.x // greetMsg.js angular.module('meetup') .component('greetMsg', { bindings: {
name: '=' }, template: ` <div ng-click="$ctrl.handleClick()"> Hey, {{$ctrl.name}} </div>`, controller() { this.handleClick = function() { this.name = 'speaker'; }; } }); // homePage.js angular.module('meetup') .component('homePage', { template: ` <h1>{{$ctrl.theName | uppercase}}</h1> <greet-msg name="$ctrl.theName"></greet-msg> `, controller() { this.theName = 'attendant'; } });
Antes Backbone var HomePageView = Backbone.View.extend({ initialize: function() { this.greetAttendants
= new GreetMsgView({ model: { name: 'attendants'} }); this.greetSpeakers = new GreetMsgView({ model: { name: 'speakers'} }); }, render: function() { this.$el.append( this.greetAttendants.render().$el, this.greetSpeakers.render().$el ); } });
Depois Angular 2.x // greetMsg.ts @Component({ selector: 'greet-msg', template: `
<div (click)="handleClick()"> Hey, {{ name }} </div> ` }) export class GreetMsg { @Input() name = ''; handleClick() { this.name = 'speakers'; } } // homePage.ts @Component({ selector: 'home-page', directives: [GreetMsg], template: ` {{ theName | uppercase }} <greet-msg [name]="theName"></greet-msg> `, }) export class HomePage { constructor() { this.theName = 'attendants'; } }
Depois Backbone ¯\_(ツ)_/¯
Funcional
const makeBoldComponent = (Component) => { return (props) => <b><Component
{...props}/></b>; }; const GreetMessage = (props) => ( <div> Hey, { props.name }. </div> ); const BoldGreetMessage = makeBoldComponent(GreetMessage); const HomePage = () => ( <div> <h1>Welcome</h1> <BoldGreetMessage name="Meetup attendant"/> </div> ); ReactDOM.render( <HomePage />, document.querySelector('#app') );
Vantagens ▸ Favorece imutabilidade e pureza ▸ Código mais limpo
e menos classes ▸ Componentes de alta ordem ▸ Reduz uso do this ▸ Mais fácil de testar ▸ Melhor performance ▸ Memoização
Antes Angular Ember Backbone Vue Knockout
Depois CycleJS Elm Reagent Om Om Deku
Fluxo único de dados
Controller Model View Antes
Action Data Component Depois
Vantagens ▸ Maior previsibilidade ▸ Mais fácil de pensar sobre
▸ Mais fácil de encontrar causa de bugs ▸ Maior escalabilidade no front-end
CycleJS Elm Redux Flux Vuex X Ember 2 Data ⬇,
actions ⬆ Relay
Virtual DOM & Tree diff V-DOM
V-DOM
Preact V-DOM Ember 2/Glimmer CycleJS RiotJS Mithril Vue 2 Inferno
Elm
React/JSX é só JavaScript
“ Interfaces de usuário são simplesmente projeções de uma forma
de dado em outra forma de dado.
Antes <ul> <li ng-repeat="item in items"> <a ng-href="{{ item.url }}">
{{ item.title }} <span ng-if="item.subtitle"> - {{ item.subtitle }} </span> </a> </li> </ul> <ul> <li v-for="item in items"> <a v-bind:href="{{ item.url }}"> {{ item.title }} <span v-if="item.subtitle"> - {{ item.subtitle }} </span> </a> </li> </ul> Angular 1.x Vue
Antes <ul> {{#each item in items}} <li> {{#link-to 'items.show' item}}
{{ item.title }} {{#if item.subtitle }} - {{ item.subtitle }} {{/if}} {{/link-to}} </li> {{/each}} </ul> Ember/Handlebars
React com JSX <ul> { items.map((item) => ( <li> <a
href={ item.url }> { item.title } { item.subtitle && `- ${ item.subtitle }` } </a> </li> )) } </ul> const linkItems = items.map((item) => ( <li> <a href={ item.url }> { item.title } { item.subtitle && `- ${ item.subtitle }` } </a> </li> )); <ul> { linkItems } </ul>
React sem JSX const h = React.createElement; h('ul', null, items.map((item)
=> ( h('li', null, h('a', { href: item.url }, item.title, item.subtitle && `- ${ item.subtitle }` ) ) )) ); const h = React.createElement; const linkItems = items.map((item) => ( h('li', null, h('a', { href: item.url }, item.title, item.subtitle && `- ${ item.subtitle }` ) ) )); h('ul', null, linkItems );
Depois h('ul', items$.map((item) => ( h('li', h('a', { href: item.url
}, [ item.title, item.subtitle && `- ${ item.subtitle }` ]) ))) ); CycleJS <ul> { items.map((item) => ( <li> <a href={ item.url }> { item.title } { item.subtitle && `- ${ item.subtitle }` } </a> </li> )) } </ul> Inferno
Depois m('ul', items.map((item) => ( m('li', m('a', { href: item.url
}, [ item.title, item.subtitle && `- ${ item.subtitle }` ]) ))) ); Mithril <ul> { items.map((item) => ( <li> <a href={ item.url }> { item.title } { item.subtitle && `- ${ item.subtitle }` } </a> </li> )) } </ul> Preact
Interoperabilidade
None
Vantagens ▸ Adoção gradual, sem reescrita ▸ Integração simples, é
só JavaScript ▸ Biblioteca focada em UI ▸ Tamanho permite ser usada em conjunto (44kb)
Renderização do front-end no server
O problema ▸ Não-SPAs carregam mais que o necessário ▸
SPAs demoram para fazer o primeiro render ▸ SPAs tem problemas com SEO (sem hacks)
A solução ▸ Renderizar o máximo do front-end no servidor
▸ “Montar” a aplicação no HTML já renderizado ▸ Carregar apenas dados a partir daí ▸ Primeira tentativa: Backbone Rendr
Com React const html = ReactDOMServer.render( <HomePage /> ); ReactDOM.render(
<HomePage />, document.querySelector('#app') ); Servidor Cliente
CycleJS Vue 2 Ember FastBoot Angular Universal
Mundo mobile
Antes: o problema ▸ Manter várias aplicações mobile inteiras é
custoso ▸ Soluções híbridas com WebView são ineficazes ▸ O mercado mobile exige apps para todos SOs
import { View, Text } from 'react-native'; const GreetMessage =
(props) => ( <Text>Hey, { props.name }</Text> ); class GreetMobileDeveloper extends Component { render() { return ( <View> <GreetMessage name="Meetup mobile developer" /> </View> ); } } Com React Native
ReactXP Depois
O futuro
create-react-app ▸ CLI para desenvolvimento com React ▸ Tooling totalmente
configurado ▸ Já vem com suporte a testes ▸ Fácil para começar a produzir na hora
React Fiber ▸ Algoritmo de renderização incremental ▸ Mudança no
agendamento da renderização ▸ Possibilidade de renderizar via stream ▸ Renderização no servidor (ainda) mais efetiva ▸ Fragments
O React-way ▸ Componentes isolados, combináveis e reutilizáveis ▸ Fluxo
único de dados ▸ Virtual DOM ▸ Somente JavaScript
“ Don’t Rewrite, React! - Ryan Florence
? Perguntas? Talysson @talyssonoc talyssonoc.github.io
Obrigado! Talysson @talyssonoc talyssonoc.github.io