SlideShare a Scribd company logo
Reconciling React as a
View Layer Replacement
Zach Lendon
@zachlendon
#reactjs #midwestjs
#reactjsisawesome
https://github.com/zachlendon/midwestjs2014
Traditional JS
MV* “issues”
•“State”
•Performance
•Complexity
•Predictability
•Testability
• Isomorphic Javascript
• The right simple :: powerful ratio
• The right configurable :: opinionated
ratio
• Pluggable modular architecture
• Performant
• SEO
Top keys to future “web” MV*
framework success
“State” of the JS MV*
Meet React
•A Javascript Library for Creating User Interfaces
•https://github.com/facebook/react
•Open Sourced and Battle-tested by Facebook and
Instagram
•Browser support to IE8
“React is not a full MVC framework, and this is actually one of its
strengths. Many who adopt React choose to do so alongside their
favorite MVC framework, like Backbone. React has no opinions
about routing or syncing data, so you can easily use your favorite
tools to handle those aspects of your frontend application. You'll
often see React used to manage specific parts of an application's UI
and not others. React really shines, however, when you fully
embrace its strategies and make it the core of your application's
interface.”
@bkonkle: http://lincolnloop.com/blog/architecting-your-app-react-part-1/
Why React?
• “State” is what makes building UIs hard
• “Data Changing over time is the Root of All Evil”
React Solution
Use composable React components that effectively
re-render themselves on each state mutation
•Apple
•Oranges
•Apple
•Grapes
•Bananas
React
Before After
Virtual DOM
•In-memory representation of the DOM and
events system
•Even HTML5 events in IE8
Advantages of Virtual DOM
•Interacting with DOM -> Slow,
•with Javascript In-Memory Objects -> fast
•60 fps fast
•Faster parsing
•Faster Validation
•Since no real browser, can easily render on server or
client
•Easier To Test
Fallout Advantages of Virtual DOM include
•Autobinding
•Event Delegation
http://lincolnloop.com/blog/architecting-your-app-react-part-1/
React Components
React Components translate raw data into rich HTML
The Ultimate State Machine
React Components
React.createClass({..})
The Ultimate State Machine
Render: “pure” Javascript function
http://jsfiddle.net/zlendon/9xyn3/
Render: “pure” Coffeescript function
http://jsfiddle.net/zlendon/32xj5/
Render: Better “pure” Coffeescript function
http://jsfiddle.net/zlendon/32xj5/1/
Render: “JSX” Javascript function
http://jsfiddle.net/zH5YG/
JSX “Desugared” to native Javascript
Rules of Render
•Return a single child component
•Native DOM component
•Composite Component
•Return predictable result each time invoked
•Does not touch the DOM (read or write) or interact with the
browser (i.e., setTimeout)
!
Rules of Server Side Render
!
!
!
!
•renderComponentToString on server
•render on client, to same node, preserves server-rendered
markup and adds event handlers
•http://www.princeton.edu/~crmarsh/react-ssr/
(Charlie Marsh)
•https://github.com/andreypopp/react-async
•https://github.com/karlmikko/bleeding-edge-
sample-app/blob/react-router/server/render/
render.js (soon to be in React-Router)
tl&dr;
React Components: Input
•Props: immutable data specific to an instance of a
component
•Like params into a function
•State: Private mutable attribute. Change within
which trigger scheduling of a component re-render
Both Props and State
• Are plain JS objects
• Changes trigger a render update
• Are deterministic. If your Component generates different outputs for
the same combination of props and state then you're doing something
wrong.
https://github.com/uberVU/react-guide/blob/master/props-vs-state.md#readme
Rules of State
•Belong to only one component
•Within that component, modified 2 ways
•getInitialState
•setState
•Render returns same result each time invoked with same
state
•Do not use computed data or duplicate prop data as state
•Avoid using state when possible
•Do not change state of children components
Rules of Props
•Passed from the parent
•Immutable
•Often pass callback functions through them
!
Component Lifecycle
Mounting
• componentWillMount()
• componentDidMount()
!
Updating
• componentWillReceiveProps(object nextProps)
• boolean shouldComponentUpdate(object nextProps, object nextState)
• componentWillUpdate(object nextProps, object nextState)
• componentDidUpdate(object prevProps, object prevState)
!
Unmounting
• componentWillUnmount()
Mixins
•Cross cutting concerns
•Examples:
•ReactScriptLoader: https://github.com/yariv/ReactScriptLoader
•ReactIntlMixin: https://github.com/yahoo/react-intl
•Backbone.React.Component.mixin: https://github.com/
magalhas/backbone-react-component
Scaling React
!
!
!
!
Action Controller Model View
Conference MVC
• Modified from Flux into by Jing Chen at F8, 2014
Scaling with React
!
!
!
!
Action Controller Model View
Model
Model
Model
Model
Model
View
View
View
View
View
View
Real World MVC
Scaling with React
!
!
!
!
Action Dispatcher Store View
Action
Flux
Starting a New App: React
•Lots of Great “Full-Stack” Starter Kit Options - Many Listed:
https://github.com/facebook/react/wiki/Complementary-Tools
New Project w/ Routing
•React Boilerplate: https://github.com/rackt/react-boilerplate
•Uses:
•React-router (prev. react-nested-router)
•Translation of Ember Router API to React
•Webpack
•pushstate-serv
New Project w/o Routing
•https://github.com/newtriks/generator-react-webpack
•Yeoman Generator
•Uses:
•Webpack
•Grunt
•Karma
New Project w/ Routing & Server-side Rendering:
•React Quickstart:
•https://github.com/newtriks/generator-react-webpack
•Uses:
•react-router-component
•react-async
•express
•browserify
•npm
New Project: Midwest JS Demo
•React Boilerplate
•Plus:
•Express (3)
•Bootstrap 3
DEMO DISCUSSION
Adding React To Existing Project
“We don’t need to switch to React everywhere, all at once. It’s
not a framework that imposes anything on the application
structure. [...] Easy, iterative adoption is definitely something
in React’s favor for us.”
!
-Adobe Brackets Team
Backbone Views
•Nested Backbone.View’s are difficult to maintain
•Every collection change re-renders all views
Simple Backbone Port
Integration with Backbone Models and Collections
•Trigger React re-render on Backbone model “change” events
Mixins! Maybe
Lost shouldComponentUpdate hooks
TODO MVC: React + Backbone
Mixins! Maybe
Backbone-React-Component
Mixins! Maybe
Backbone-React-Component
Use State Callback
Use State Callback
Angular and React
Angular Directives Wrapping React
•ngReact
•ngReactGrid
Angular ngReactGrid Demo
Integration Lessons
•You can integrate React with other frameworks
•Backbone integration works better than many options since re-
rendering on model state change is the typical Backbone
approach
•Angular will work best from directives but is a bit of a force fit
•Best approach to let React own the DOM element being
rendered into
(Beyond the Obvious) Additional Resources (1/2)
•Great Collection of Community links:

https://github.com/mindreframer/reactjs-stuff
•Developing User Interfaces with React: http://youtu.be/
1OeXsL5mr4g?list=PLuE9Gq9Mxr5kCvVa7tcwW1S2-FEym5fbt
(intro + good performance demo)
•Good Flux intro by Ryan Florence: http://vimeo.com/
102953099
•Thorough and infamous Angular/ReactJS performance/
integration post: http://www.williambrownstreet.net/blog/
2014/04/faster-angularjs-rendering-angularjs-and-reactjs/
•Performance Tools: http://facebook.github.io/react/docs/
perf.html
!
(Beyond the Obvious) Additional Resources (2/2)
!
•Webpack Howto: https://github.com/petehunt/webpack-
howto
•Webpack Hot Module Replacement: https://github.com/
webpack/docs/wiki/hot-module-replacement-with-webpack
•Om: https://github.com/swannodette/om
•Jest: http://facebook.github.io/jest/
Thank You
Questions?
Zach Lendon
@zachlendon
#reactjs #midwestjs
https://github.com/zachlendon
#reactjs on freenode

More Related Content

PPT
Starting with Reactjs
PPTX
React native - React(ive) Way To Build Native Mobile Apps
PPTX
React js Online Training
PDF
Using React with Grails 3
PPTX
001. Introduction about React
PDF
Introduce flux & react in practice
PPTX
React in production (react global summit 2021)
Starting with Reactjs
React native - React(ive) Way To Build Native Mobile Apps
React js Online Training
Using React with Grails 3
001. Introduction about React
Introduce flux & react in practice
React in production (react global summit 2021)

What's hot (20)

PDF
Workshop React.js
PPTX
Isomorphic JavaScript – future of the web
PDF
"The Story of Declarative React at Grammarly: From two-way data binding with ...
PDF
React vs angular
PDF
The Dark Side of Single Page Applications
PDF
Intro JavaScript
PPTX
React JS: A Secret Preview
PDF
React.js - and how it changed our thinking about UI
PDF
Introduction to react
PPTX
React js basics
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
PPSX
React introduction
PPTX
Gradle Again
PPTX
Reactjs workshop
PPTX
An Angular developer moving to React
PPTX
Reactjs
PDF
Application Architectures in Grails
PPTX
Angular on ASP.NET MVC 6
PDF
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
PPTX
One code Web, iOS, Android
Workshop React.js
Isomorphic JavaScript – future of the web
"The Story of Declarative React at Grammarly: From two-way data binding with ...
React vs angular
The Dark Side of Single Page Applications
Intro JavaScript
React JS: A Secret Preview
React.js - and how it changed our thinking about UI
Introduction to react
React js basics
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
React introduction
Gradle Again
Reactjs workshop
An Angular developer moving to React
Reactjs
Application Architectures in Grails
Angular on ASP.NET MVC 6
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
One code Web, iOS, Android
Ad

Viewers also liked (20)

PPT
Podizanje zasada lijeske i ekonomska isplativost[1]
PPTX
React and Flux life cycle with JSX, React Router and Jest Unit Testing
PDF
Management Consulting
PPTX
ReactJs
PPTX
Oprah Winfrey
PPTX
Medical devices
PDF
ReactJS | 서버와 클라이어트에서 동시에 사용하는
PPTX
Elon Musk
PPT
Bill Gates, Who is he?
PDF
Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014
PPT
Reverse Engineering
PDF
Chess
PPT
Lionel Messi
PPT
Lionel messi
PPTX
Product management
PDF
Product Management
PDF
Personal Development
PPTX
Unit Test JavaScript
PDF
Intro to React - Featuring Modern JavaScript
ODP
Hadoop and Cassandra at Rackspace
Podizanje zasada lijeske i ekonomska isplativost[1]
React and Flux life cycle with JSX, React Router and Jest Unit Testing
Management Consulting
ReactJs
Oprah Winfrey
Medical devices
ReactJS | 서버와 클라이어트에서 동시에 사용하는
Elon Musk
Bill Gates, Who is he?
Simo Ahava - Tag Management Solutions – Best. Data. Ever. MKTFEST 2014
Reverse Engineering
Chess
Lionel Messi
Lionel messi
Product management
Product Management
Personal Development
Unit Test JavaScript
Intro to React - Featuring Modern JavaScript
Hadoop and Cassandra at Rackspace
Ad

Similar to Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014) (20)

PDF
Tech Talk on ReactJS
PPTX
React.js at Cortex
PDF
React & Flux Workshop
PDF
FRONTEND DEVELOPMENT WITH REACT.JS
PDF
An Overview of the React Ecosystem
PDF
An Intense Overview of the React Ecosystem
PPTX
Up and Running with ReactJS
PDF
React js
PPTX
Adding a modern twist to legacy web applications
PDF
Server side rendering with React and Symfony
PDF
React Tech Salon
PPTX
PPTX
React js
PDF
Workshop 19: ReactJS Introduction
PPTX
React, Flux and more (p1)
PPTX
React + Flux = Joy
PDF
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
PPTX
ReactJS - Re-rendering pages in the age of the mutable DOM
PPTX
PDF
React Fundamentals - Jakarta JS, Apr 2016
Tech Talk on ReactJS
React.js at Cortex
React & Flux Workshop
FRONTEND DEVELOPMENT WITH REACT.JS
An Overview of the React Ecosystem
An Intense Overview of the React Ecosystem
Up and Running with ReactJS
React js
Adding a modern twist to legacy web applications
Server side rendering with React and Symfony
React Tech Salon
React js
Workshop 19: ReactJS Introduction
React, Flux and more (p1)
React + Flux = Joy
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
ReactJS - Re-rendering pages in the age of the mutable DOM
React Fundamentals - Jakarta JS, Apr 2016

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25-Week II
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Group 1 Presentation -Planning and Decision Making .pptx
Machine Learning_overview_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
A comparative analysis of optical character recognition models for extracting...
Per capita expenditure prediction using model stacking based on satellite ima...

Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)

  • 1. Reconciling React as a View Layer Replacement Zach Lendon @zachlendon #reactjs #midwestjs #reactjsisawesome https://github.com/zachlendon/midwestjs2014
  • 2. Traditional JS MV* “issues” •“State” •Performance •Complexity •Predictability •Testability • Isomorphic Javascript • The right simple :: powerful ratio • The right configurable :: opinionated ratio • Pluggable modular architecture • Performant • SEO Top keys to future “web” MV* framework success “State” of the JS MV*
  • 3. Meet React •A Javascript Library for Creating User Interfaces •https://github.com/facebook/react •Open Sourced and Battle-tested by Facebook and Instagram •Browser support to IE8
  • 4. “React is not a full MVC framework, and this is actually one of its strengths. Many who adopt React choose to do so alongside their favorite MVC framework, like Backbone. React has no opinions about routing or syncing data, so you can easily use your favorite tools to handle those aspects of your frontend application. You'll often see React used to manage specific parts of an application's UI and not others. React really shines, however, when you fully embrace its strategies and make it the core of your application's interface.” @bkonkle: http://lincolnloop.com/blog/architecting-your-app-react-part-1/
  • 5. Why React? • “State” is what makes building UIs hard • “Data Changing over time is the Root of All Evil”
  • 6. React Solution Use composable React components that effectively re-render themselves on each state mutation
  • 8. Virtual DOM •In-memory representation of the DOM and events system •Even HTML5 events in IE8
  • 9. Advantages of Virtual DOM •Interacting with DOM -> Slow, •with Javascript In-Memory Objects -> fast •60 fps fast •Faster parsing •Faster Validation •Since no real browser, can easily render on server or client •Easier To Test
  • 10. Fallout Advantages of Virtual DOM include •Autobinding •Event Delegation
  • 12. React Components React Components translate raw data into rich HTML The Ultimate State Machine
  • 14. Render: “pure” Javascript function http://jsfiddle.net/zlendon/9xyn3/
  • 15. Render: “pure” Coffeescript function http://jsfiddle.net/zlendon/32xj5/
  • 16. Render: Better “pure” Coffeescript function http://jsfiddle.net/zlendon/32xj5/1/
  • 17. Render: “JSX” Javascript function http://jsfiddle.net/zH5YG/
  • 18. JSX “Desugared” to native Javascript
  • 19. Rules of Render •Return a single child component •Native DOM component •Composite Component •Return predictable result each time invoked •Does not touch the DOM (read or write) or interact with the browser (i.e., setTimeout) !
  • 20. Rules of Server Side Render ! ! ! ! •renderComponentToString on server •render on client, to same node, preserves server-rendered markup and adds event handlers •http://www.princeton.edu/~crmarsh/react-ssr/ (Charlie Marsh) •https://github.com/andreypopp/react-async •https://github.com/karlmikko/bleeding-edge- sample-app/blob/react-router/server/render/ render.js (soon to be in React-Router) tl&dr;
  • 21. React Components: Input •Props: immutable data specific to an instance of a component •Like params into a function •State: Private mutable attribute. Change within which trigger scheduling of a component re-render
  • 22. Both Props and State • Are plain JS objects • Changes trigger a render update • Are deterministic. If your Component generates different outputs for the same combination of props and state then you're doing something wrong. https://github.com/uberVU/react-guide/blob/master/props-vs-state.md#readme
  • 23. Rules of State •Belong to only one component •Within that component, modified 2 ways •getInitialState •setState •Render returns same result each time invoked with same state •Do not use computed data or duplicate prop data as state •Avoid using state when possible •Do not change state of children components
  • 24. Rules of Props •Passed from the parent •Immutable •Often pass callback functions through them !
  • 25. Component Lifecycle Mounting • componentWillMount() • componentDidMount() ! Updating • componentWillReceiveProps(object nextProps) • boolean shouldComponentUpdate(object nextProps, object nextState) • componentWillUpdate(object nextProps, object nextState) • componentDidUpdate(object prevProps, object prevState) ! Unmounting • componentWillUnmount()
  • 26. Mixins •Cross cutting concerns •Examples: •ReactScriptLoader: https://github.com/yariv/ReactScriptLoader •ReactIntlMixin: https://github.com/yahoo/react-intl •Backbone.React.Component.mixin: https://github.com/ magalhas/backbone-react-component
  • 27. Scaling React ! ! ! ! Action Controller Model View Conference MVC • Modified from Flux into by Jing Chen at F8, 2014
  • 28. Scaling with React ! ! ! ! Action Controller Model View Model Model Model Model Model View View View View View View Real World MVC
  • 29. Scaling with React ! ! ! ! Action Dispatcher Store View Action Flux
  • 30. Starting a New App: React •Lots of Great “Full-Stack” Starter Kit Options - Many Listed: https://github.com/facebook/react/wiki/Complementary-Tools
  • 31. New Project w/ Routing •React Boilerplate: https://github.com/rackt/react-boilerplate •Uses: •React-router (prev. react-nested-router) •Translation of Ember Router API to React •Webpack •pushstate-serv
  • 32. New Project w/o Routing •https://github.com/newtriks/generator-react-webpack •Yeoman Generator •Uses: •Webpack •Grunt •Karma
  • 33. New Project w/ Routing & Server-side Rendering: •React Quickstart: •https://github.com/newtriks/generator-react-webpack •Uses: •react-router-component •react-async •express •browserify •npm
  • 34. New Project: Midwest JS Demo •React Boilerplate •Plus: •Express (3) •Bootstrap 3
  • 36. Adding React To Existing Project “We don’t need to switch to React everywhere, all at once. It’s not a framework that imposes anything on the application structure. [...] Easy, iterative adoption is definitely something in React’s favor for us.” ! -Adobe Brackets Team
  • 37. Backbone Views •Nested Backbone.View’s are difficult to maintain •Every collection change re-renders all views
  • 39. Integration with Backbone Models and Collections •Trigger React re-render on Backbone model “change” events
  • 40. Mixins! Maybe Lost shouldComponentUpdate hooks TODO MVC: React + Backbone
  • 46. Angular Directives Wrapping React •ngReact •ngReactGrid
  • 48. Integration Lessons •You can integrate React with other frameworks •Backbone integration works better than many options since re- rendering on model state change is the typical Backbone approach •Angular will work best from directives but is a bit of a force fit •Best approach to let React own the DOM element being rendered into
  • 49. (Beyond the Obvious) Additional Resources (1/2) •Great Collection of Community links:
 https://github.com/mindreframer/reactjs-stuff •Developing User Interfaces with React: http://youtu.be/ 1OeXsL5mr4g?list=PLuE9Gq9Mxr5kCvVa7tcwW1S2-FEym5fbt (intro + good performance demo) •Good Flux intro by Ryan Florence: http://vimeo.com/ 102953099 •Thorough and infamous Angular/ReactJS performance/ integration post: http://www.williambrownstreet.net/blog/ 2014/04/faster-angularjs-rendering-angularjs-and-reactjs/ •Performance Tools: http://facebook.github.io/react/docs/ perf.html !
  • 50. (Beyond the Obvious) Additional Resources (2/2) ! •Webpack Howto: https://github.com/petehunt/webpack- howto •Webpack Hot Module Replacement: https://github.com/ webpack/docs/wiki/hot-module-replacement-with-webpack •Om: https://github.com/swannodette/om •Jest: http://facebook.github.io/jest/
  • 51. Thank You Questions? Zach Lendon @zachlendon #reactjs #midwestjs https://github.com/zachlendon #reactjs on freenode