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
Data driven rendering
Search
Marc Tamlyn
February 17, 2016
Technology
220
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
More Decks by Marc Tamlyn
See All by Marc Tamlyn
Arousal and Anxiety
mjtamlyn
1
120
Working with Children
mjtamlyn
1
110
Wallingford Castle Archers Incorporation
mjtamlyn
0
230
Observation and Evaluation
mjtamlyn
0
150
Weird and Wonderful things to do with the ORM
mjtamlyn
3
1.5k
An Introduction to Graphene and Relay
mjtamlyn
6
1.2k
Tech Interviews that don't suck
mjtamlyn
4
1.2k
What's new in Django 1.9
mjtamlyn
1
230
Django Development Milestones
mjtamlyn
1
200
Other Decks in Technology
See All in Technology
Agentic Web
dynamis
1
210
Android の公式 Skill / Android skills
yanzm
0
140
手塩にかけりゃいいってもんじゃない
ming_ayami
0
550
LLMにもCAP定理があるという話
harukasakihara
0
310
気づかぬうちにセキュリティ負債を生むAPIキー運用
sgwrmctk
0
110
スキルと MCP ツール、責務をどう分けるか? AI が迷わないインターフェース設計の戦略
cdataj
1
1k
AmazonRoute 53ではじめてのドメイン取得!HTTPS化までの道のりを整理してみた
usanchuu
3
130
データサイエンスを価値につなげるプロジェクト設計 〜 DS一年目が現場で得た気づき 〜
ysd113
1
220
就職⽀援サービスにおけるキャリアアドバイザーのシフトスケジューリング
recruitengineers
PRO
1
140
Building applications in the Gemini API family.
line_developers_tw
PRO
0
3.2k
フロンティアAIのゲート化と地政学リスク
nagatsu
0
130
【Cyber-sec+】経営層を"動かす"ための考え方
hssh2_bin
0
150
Featured
See All Featured
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
160
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
390
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Building an army of robots
kneath
306
46k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
200
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
Color Theory Basics | Prateek | Gurzu
gurzu
0
360
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Transcript
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