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
Data driven rendering
Search
Marc Tamlyn
February 17, 2016
Technology
240
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Data driven rendering
An introduction to ReactJS given at JSOxford
Marc Tamlyn
February 17, 2016
Transcript
21 slides
Data driven rendering An introduction to ReactJS Marc Tamlyn Photo
by Konstans Zafeiri on photocrowd.com
None
This is not •Babel •Webpack •Browserify •Flux •Redux •Relay
Motivation
None
Motivation •Responsive to input changes •Interactivity •Rendering only •Not a
jQuery mess!
What is React? •View layer of a traditional MVC •Virtual
DOM •Single directional data flow
What is a Component? •Takes input (props) •Returns an element
•Class with a render() method
What is a Component? var Photo = React.createClass({ render: function()
{ return React.createElement('img', { src: this.props.imageSrc, }); } });
Components with children var Photos = React.createClass({ render: function() {
var photos = this.props.photos.map((photo) => { return React.createElement(Photo, { imageSrc: photo.imageSrc, }); }); return React.createElement('div', {}, photos); } });
JSX •Preprocessor for React.createElement() •Compile using your JS preprocessor of
choice
JSX var Photos = React.createClass({ render: function() { var photos
= this.props.photos.map((photo) => { return <Photo imageSrc={photo.imageSrc} /> }); return <div>{photos}</div>; } });
Virtual DOM •Renders in memory-light virtual DOM •Compares changes between
trees •Flushes only changes to the document •Debounces rendering
Data flow •Components have state as well as props •Minimise
use of state •Handle at top level and pass functions around •Handle externally altogether!
Data flow var Photos = React.createClass({ getInitialState: function() { return
{photos: this.props.photos}; }, onLove: function() { … }, render: function() { var photos = this.state.photos.map((photo) => { return <Photo imageSrc={photo.imageSrc} onLove={this.onLove} /> }); return <div>{photos}</div>; } });
Data flow var Photo = React.createClass({ render: function() { return
<div> <img src={this.props.imageSrc} /> <a onclick={this.props.onLove}>Love</a> </div>; } });
Data flow •YOUR CHOICE •External communication
Example time!
$.fn.reactify <div data-react-component="Photos" data-react-props="{{ photos_json }}"></div> <script> $(document).reactify(); </script>
Work with us photocrowd.com/jobs
Thank you github.com/mjtamlyn twitter.com/mjtamlyn photocrowd.com/mjtamlyn
More Decks by Marc Tamlyn
See All by Marc Tamlyn
Arousal and Anxiety
mjtamlyn
1
150
Working with Children
mjtamlyn
1
130
Wallingford Castle Archers Incorporation
mjtamlyn
0
260
Observation and Evaluation
mjtamlyn
0
170
Weird and Wonderful things to do with the ORM
mjtamlyn
3
1.5k
An Introduction to Graphene and Relay
mjtamlyn
6
1.3k
Tech Interviews that don't suck
mjtamlyn
4
1.2k
What's new in Django 1.9
mjtamlyn
1
240
Django Development Milestones
mjtamlyn
1
210
Other Decks in Technology
See All in Technology
攻撃と守りは何が変わり、何が変わらないのか~最近の不正アクセスから考える、リスク評価と標準の使いどころ
oidfj
2
320
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
260
Terraform 0 to 100:100個以上のリポジトリを常に最新にし続けるための自動化
sue445
3
1.4k
コーディングできない僕にBobが舞い降りた
shumpei3
0
200
Context parameters で作る!はじめての型クラス
kworkdev
PRO
1
180
ポケモンバトルのAIエージェント
koji_kawamura
0
230
技術書典で本を売る流れ
yoshimura_datam
0
140
MCPでネットワーク障害調査を自動化する前に直すべき3つのこと
yama3133
1
660
クラウドでも使えるNetApp -現場目線での設計とクラウドバックアップの活用
ryutakondo
1
330
OpenTelemetryで変わった 新時代のCloudWatchメトリクス監視
tsukuboshi
0
500
統制されたID・権限をどう利用するか : DPoP/FAPIによるAPIセキュリティ強化
oidfj
2
300
目を覚ませ!僕らの認証情報が何者かに侵略されてるぞ
tkito
2
490
Featured
See All Featured
So, you think you're a good person
axbom
PRO
2
2.3k
Optimizing for Happiness
mojombo
378
72k
What the history of the web can teach us about the future of AI
inesmontani
PRO
3
830
Heart Work Chapter 1 - Part 1
lfama
PRO
11
37k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.9k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
820
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
320
Chasing Engaging Ingredients in Design
codingconduct
0
410
WCS-LA-2024
lcolladotor
0
1k
Abbi's Birthday
coloredviolet
5
11k