REACT.JS : Rethinking UI Development Using JavaScript

110
REACT.JS RETHINKING UI DEVELOPMENT WITH JAVASCRIPT Introduction

Transcript of REACT.JS : Rethinking UI Development Using JavaScript

Page 1: REACT.JS : Rethinking UI Development Using JavaScript

REACT.JS RETHINKING UI DEVELOPMENT WITH JAVASCRIPT

Introduction

Page 2: REACT.JS : Rethinking UI Development Using JavaScript

AgendaOverviewComponentsJSXData for componentThe component lifecycleComponent MethodsComponent BreakdownReact v0.14Flux (Intro)

Page 3: REACT.JS : Rethinking UI Development Using JavaScript

React: Overview

Page 4: REACT.JS : Rethinking UI Development Using JavaScript

A powerful framework by FB

Page 5: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

Page 6: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

Page 7: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

“The way we are able to figure this out is that React does not manipulate the DOM unless it needs to. It uses a fast, internal mock DOM to perform diffs and computes the most efficient DOM mutation for you.”

- React Doc

Page 8: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

var msg = 'Bad';

$userMsg.html( '<p>I love Breaking ' + msg );

var data = { 'user_id' : 13, 'user_name' : 'W.W', 'user_msg' : 'I am the one who knocks!'};

$chatList.append( [ '<li class="chat__msg-wrap">', '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>', '<span class="chat__user-name">' + data.user_name + '</span>', '<span class="chat__user-msg">' + data.user_msg + '</span>', '</li>' ].join(););

Page 9: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

var msg = 'Bad';

$userMsg.html( '<p>I love Breaking ' + msg );

var data = { 'user_id' : 13, 'user_name' : 'W.W', 'user_msg' : 'I am the one who knocks!'};

$chatList.append( [ '<li class="chat__msg-wrap">', '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>', '<span class="chat__user-name">' + data.user_name + '</span>', '<span class="chat__user-msg">' + data.user_msg + '</span>', '</li>' ].join(););

Page 10: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

Page 11: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

Page 12: REACT.JS : Rethinking UI Development Using JavaScript

❖ Implements a virtual DOM

❖ Allows us to render components super fast

❖ Removes any unnecessary overhead from DOM operations

❖ Deal with the "V" of any MVC framework

Page 13: REACT.JS : Rethinking UI Development Using JavaScript
Page 14: REACT.JS : Rethinking UI Development Using JavaScript

Components

Page 15: REACT.JS : Rethinking UI Development Using JavaScript

Special functionality unit

Page 16: REACT.JS : Rethinking UI Development Using JavaScript

❖ Each component is contained in its own "scope"

❖ Define the functionality and reuse it as many times

❖ Has a render function, which returns the HTML the component will

render in the browser

❖ We can call other React component's too

Page 17: REACT.JS : Rethinking UI Development Using JavaScript

❖ Each component is contained in its own "scope"

❖ Define the functionality and reuse it as many times

❖ Has a render function, which returns the HTML the component will

render in the browser

❖ We can call other React component's too

Page 18: REACT.JS : Rethinking UI Development Using JavaScript

❖ Each component is contained in its own "scope"

❖ Define the functionality and reuse it as many times

❖ Has a render function, which returns the HTML the component will

render in the browser

❖ We can call other React component's too

Page 19: REACT.JS : Rethinking UI Development Using JavaScript

❖ Each component is contained in its own "scope"

❖ Define the functionality and reuse it as many times

❖ Has a render function, which returns the HTML the component will

render in the browser

❖ We can call other React component's too

Page 20: REACT.JS : Rethinking UI Development Using JavaScript

❖ Each component is contained in its own "scope"

❖ Define the functionality and reuse it as many times

❖ Has a render function, which returns the HTML the component will

render in the browser

❖ We can call other React component's too

Page 21: REACT.JS : Rethinking UI Development Using JavaScript

JSX

Page 22: REACT.JS : Rethinking UI Development Using JavaScript

HTML inside of JS

Page 23: REACT.JS : Rethinking UI Development Using JavaScript

❖ Write HTML inside of Javascript without having to wrap strings around it

❖ We don't have to worry about strings and multiple lines etc

❖ Transform the JSX in the browser on runtime - not recommended as it slows down

your page

❖ Both gulp and grunt offer a JSX transformer

Page 24: REACT.JS : Rethinking UI Development Using JavaScript

❖ Write HTML inside of Javascript without having to wrap strings around it

❖ We don't have to worry about strings and multiple lines etc

❖ Transform the JSX in the browser on runtime - not recommended as it slows down

your page

❖ Both gulp and grunt offer a JSX transformer

Page 25: REACT.JS : Rethinking UI Development Using JavaScript

❖ Write HTML inside of Javascript without having to wrap strings around it

❖ We don't have to worry about strings and multiple lines etc

❖ Transform the JSX in the browser on runtime - not recommended as it slows down

your page

❖ Both gulp and grunt offer a JSX transformer

Page 26: REACT.JS : Rethinking UI Development Using JavaScript

$chatList.append( '<li class="chat__msg-wrap"> <img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/> <span class="chat__user-name">' + data.user_name + '</span> <span class="chat__user-msg">' + data.user_msg + '</span> </li>' );

$chatList.append( '<li class="chat__msg-wrap">' + '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>' + '<span class="chat__user-name">' + data.user_name + '</span>' + '<span class="chat__user-msg">' + data.user_msg + '</span>' + '</li>');

$chatList.append( [ '<li class="chat__msg-wrap">', '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>', '<span class="chat__user-name">' + data.user_name + '</span>', '<span class="chat__user-msg">' + data.user_msg + '</span>', '</li>' ].join(););

Page 27: REACT.JS : Rethinking UI Development Using JavaScript

$chatList.append( '<li class="chat__msg-wrap"> <img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/> <span class="chat__user-name">' + data.user_name + '</span> <span class="chat__user-msg">' + data.user_msg + '</span> </li>' );

$chatList.append( '<li class="chat__msg-wrap">' + '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>' + '<span class="chat__user-name">' + data.user_name + '</span>' + '<span class="chat__user-msg">' + data.user_msg + '</span>' + '</li>');

$chatList.append( [ '<li class="chat__msg-wrap">', '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>', '<span class="chat__user-name">' + data.user_name + '</span>', '<span class="chat__user-msg">' + data.user_msg + '</span>', '</li>' ].join(););

Page 28: REACT.JS : Rethinking UI Development Using JavaScript

$chatList.append( '<li class="chat__msg-wrap"> <img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/> <span class="chat__user-name">' + data.user_name + '</span> <span class="chat__user-msg">' + data.user_msg + '</span> </li>' );

$chatList.append( '<li class="chat__msg-wrap">' + '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>' + '<span class="chat__user-name">' + data.user_name + '</span>' + '<span class="chat__user-msg">' + data.user_msg + '</span>' + '</li>');

$chatList.append( [ '<li class="chat__msg-wrap">', '<img class="chat__user-img" src="' + getUserImg(data.user_id) + '"/>', '<span class="chat__user-name">' + data.user_name + '</span>', '<span class="chat__user-msg">' + data.user_msg + '</span>', '</li>' ].join(););

Page 29: REACT.JS : Rethinking UI Development Using JavaScript

❖ Write HTML inside of Javascript without having to wrap strings around it

❖ We don't have to worry about strings and multiple lines etc

❖ Transform the JSX in the browser on runtime - not recommended as it slows down

your page

❖ Both gulp and grunt offer a JSX transformer

Page 30: REACT.JS : Rethinking UI Development Using JavaScript

❖ Write HTML inside of Javascript without having to wrap strings around it

❖ We don't have to worry about strings and multiple lines etc

❖ Transform the JSX in the browser on runtime - not recommended as it slows down

your page

❖ Both gulp and grunt offer a JSX transformer

Page 31: REACT.JS : Rethinking UI Development Using JavaScript

Using JSX

Page 32: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ render: function () { return ( <div className="navigation"> Hello World! </div> ); }});

Page 33: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ render: function () { return ( React.createElement('div', {className: 'navigation'}, 'Hello World!') ); }});

❖ You don't have to use JSX

❖ Using className since class is a reserved word in Javascript

❖ JSX transforms the code, changes all the attributes on the node into an object

Page 34: REACT.JS : Rethinking UI Development Using JavaScript

Using variables for attributes

Page 35: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ render: function () { var navigationClass = 'navigation'; return ( <div className={ navigationClass }> Hello World! </div> ); }});

❖ Dynamically change the class of a component

❖ Wrap it around a set of curly braces, so JSX knows that it is an external variable

Page 36: REACT.JS : Rethinking UI Development Using JavaScript

The Initial Render

Page 37: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ render: function () { var navigationClass = 'navigation'; return ( <div className={ navigationClass }> Hello World! </div> ); }});

ReactDOM.render( <ExampleComponent />, document.body );

❖ Tell React which component to render, and point to an existing DOM node for where

to render it

Page 38: REACT.JS : Rethinking UI Development Using JavaScript

Data for component

Page 39: REACT.JS : Rethinking UI Development Using JavaScript

Props and States

Page 40: REACT.JS : Rethinking UI Development Using JavaScript

Props

Page 41: REACT.JS : Rethinking UI Development Using JavaScript

❖ Props is the data passed into a component

❖ Props is accessed via “this.props”

❖ Props is immutable, don’t change only use

Page 42: REACT.JS : Rethinking UI Development Using JavaScript

❖ Props is the data passed into a component

❖ Props is accessed via “this.props”

❖ Props is immutable, don’t change only use

Page 43: REACT.JS : Rethinking UI Development Using JavaScript

❖ Props is the data passed into a component

❖ Props is accessed via “this.props”

❖ Props is immutable, don’t change only use

Page 44: REACT.JS : Rethinking UI Development Using JavaScript

❖ Props is the data passed into a component

❖ Props is accessed via “this.props”

❖ Props is immutable, don’t change only use

Page 45: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ render: function () { return ( <div className="say-hello"> Hello { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 46: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ render: function () { return ( <div className="say-hello"> Hello { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 47: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ render: function () { return ( <div className="say-hello"> Hello { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 48: REACT.JS : Rethinking UI Development Using JavaScript

State

Page 49: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 50: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 51: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 52: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 53: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 54: REACT.JS : Rethinking UI Development Using JavaScript

❖ State is the private data within each instance of components

❖ State is accessed via “this.state”

❖ State is mutable, do whatever we want

❖ Usually we hook those data into state that represent UI

❖ Changing state will re-render UI

Page 55: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ getInitalState: function () { return { greet: 'Hello' } }, render: function () { return ( <div className="say-hello"> { this.state.greet } { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 56: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ getInitalState: function () { return { greet: 'Hello' } }, render: function () { return ( <div className="say-hello"> { this.state.greet } { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 57: REACT.JS : Rethinking UI Development Using JavaScript

var SayMyName = React.createClass({ getInitalState: function () { return { greet: 'Hello' } }, render: function () { return ( <div className="say-hello"> { this.state.greet } { this.props.name } </div> ); }});

var myName = 'Heisenberg';

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 58: REACT.JS : Rethinking UI Development Using JavaScript

The component lifecycle

Page 59: REACT.JS : Rethinking UI Development Using JavaScript

getInitialStateonly called once, and is called as the component is being mounted.

Page 60: REACT.JS : Rethinking UI Development Using JavaScript

componentWillMountAs soon as your component is about to be mounted, this is called.

Page 61: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ componentWillMount: function () { // hide any loading screens // remove any placeholders }, render: function () { // this gets called many times in a components life return ( <div> Hello World! </div> ); }});

Page 62: REACT.JS : Rethinking UI Development Using JavaScript

componentDidMountOnce your component has ran the render function and actually rendered your component in the DOM

Page 63: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ componentDidMount: function () { // render a chart on the DOM node // bind events to window, like resize }, render: function () { return ( <div> Hello World! </div> ); }});

Page 64: REACT.JS : Rethinking UI Development Using JavaScript

componentWillUnmountIf you were to remove the component from the DOM, this function is called

Page 65: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleComponent = React.createClass({ componentWillUnmount: function () { // unbind events to window, like resize }, render: function () { return ( <div> Hello World! </div> ); }});

Page 66: REACT.JS : Rethinking UI Development Using JavaScript

Component Methods

Page 67: REACT.JS : Rethinking UI Development Using JavaScript

getDefaultPropsDefine the default values for the properties of the component that we are expecting

Page 68: REACT.JS : Rethinking UI Development Using JavaScript

var Navigation = React.createClass({ getDefaultProps: function () { return { nav: {} } }, render: function () { return ( <ul className="navigation">...</ul> ); }});

ReactDOM.render( <Navigation nav={ navObj } />, $header );ReactDOM.render( <Navigation />, $footer );

Page 69: REACT.JS : Rethinking UI Development Using JavaScript

propTypesSpecify the type of each property we are expecting for validation. Checked only in development mode.

Page 70: REACT.JS : Rethinking UI Development Using JavaScript

var Navigation = React.createClass({ propTypes: { nav : React.PropTypes.object, data : React.PropTypes.array }, render: function () { return ( <ul className="navigation">...</ul> ); }});

ReactDOM.render( <Navigation nav={ navObj } />, $header );

Page 71: REACT.JS : Rethinking UI Development Using JavaScript

mixinsSo we don't have to write the same code twice

Page 72: REACT.JS : Rethinking UI Development Using JavaScript

var ExampleMixin = { componentDidMount: function () { // bind resize event on window }, componentWillUnmount: function () { // unbind resize event from window }};

var ExampleComponent = React.createClass({ mixins: [ExampleMixin]});

var AnotherComponent = React.createClass({ mixins: [ExampleMixin]});

Page 73: REACT.JS : Rethinking UI Development Using JavaScript

Loop de loopLooping through data in array of objects

Page 74: REACT.JS : Rethinking UI Development Using JavaScript

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <li className="navigation__item"> <a className="navigation__link" href={ item.href }> { item.text } </a> </li> ); });

return ( <ul className="navigation"> { items } </ul> ); }});

var navObj = [{ href: 'http://vijaydev.com', text: 'My Website'}];

ReactDOM.render( <Navigation nav={ navObj } />, $header );

Page 75: REACT.JS : Rethinking UI Development Using JavaScript

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <li className="navigation__item"> <a className="navigation__link" href={ item.href }> { item.text } </a> </li> ); });

return ( <ul className="navigation"> { items } </ul> ); }});

var navObj = [{ href: 'http://vijaydev.com', text: 'My Website'}];

ReactDOM.render( <Navigation nav={ navObj } />, $header );

Page 76: REACT.JS : Rethinking UI Development Using JavaScript

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <li className="navigation__item"> <a className="navigation__link" href={ item.href }> { item.text } </a> </li> ); });

return ( <ul className="navigation"> { items } </ul> ); }});

var navObj = [{ href: 'http://vijaydev.com', text: 'My Website'}];

ReactDOM.render( <Navigation nav={ navObj } />, $header );

Page 77: REACT.JS : Rethinking UI Development Using JavaScript

var NavItem = React.createClass({ render: function () { return ( <li className="navigation__item"> <a className="navigation__link" href={ this.props.href }> { this.props.text } </a> </li> ); }});

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <NavItem href={ item.href } text={ item.text } /> ); });

return ( <ul className="navigation">{ items }</ul> ); }});

Page 78: REACT.JS : Rethinking UI Development Using JavaScript

var NavItem = React.createClass({ render: function () { return ( <li className="navigation__item"> <a className="navigation__link" href={ this.props.href }> { this.props.text } </a> </li> ); }});

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <NavItem href={ item.href } text={ item.text } /> ); });

return ( <ul className="navigation">{ items }</ul> ); }});

Page 79: REACT.JS : Rethinking UI Development Using JavaScript

var NavItem = React.createClass({ render: function () { return ( <li className="navigation__item"> <a className="navigation__link" href={ this.props.href }> { this.props.text } </a> </li> ); }});

var Navigation = React.createClass({ render: function () { var items = this.props.nav.map(function (item) { return ( <NavItem href={ item.href } text={ item.text } /> ); });

return ( <ul className="navigation">{ items }</ul> ); }});

Page 80: REACT.JS : Rethinking UI Development Using JavaScript

Component Breakdown

Page 81: REACT.JS : Rethinking UI Development Using JavaScript

UI to reusable componentsCase study: How to breakdown UI into various reusable components

Page 82: REACT.JS : Rethinking UI Development Using JavaScript
Page 83: REACT.JS : Rethinking UI Development Using JavaScript

data = [{ 'src' : '/path/to/image', 'alt' : 'alt text of image', 'title' : 'name of the movie', 'href' : '/path/to/the/movie/details/page', 'cast' : ['array', 'of', 'movie', 'casts'], 'rating' : 'movie rating', 'theater_href' : '/path/to/theater/list' }, { ... ... }, { ... ... }];

Page 84: REACT.JS : Rethinking UI Development Using JavaScript

props = [{ 'src' : '/path/to/image', 'alt' : 'alt text of image', 'title' : 'name of the movie', 'href' : '/path/to/the/movie/details/page', 'cast' : ['array', 'of', 'movie', 'casts'], 'rating' : 'movie rating', 'theater_href' : '/path/to/theater/list' }, {...}, {...}];

state = { 'actualData' : this.props, 'currWidth' : 'calculated current screen width', 'colCount' : 'based on currWidth & max column count', 'perPage' : 'based on currWidth & colCount', 'totalPages' : 'based on perPage & actualData length', 'currPageNo' : 'used in calculating pageData', 'pageData' : 'based on totalPages & currPageNo' };

Page 85: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

Page 86: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

props = [{ 'src' : '/path/to/image', 'alt' : 'alt text of image', 'title' : 'name of the movie', 'href' : '/path/to/the/movie/details/page', 'cast' : ['array', 'of', 'movie', 'casts'], 'rating' : 'movie rating', 'theater_href' : '/path/to/theater/list' }, {...}, {...}];

state = { 'actualData' : this.props, 'currWidth' : 'calculated current screen width', 'colCount' : 'based on currWidth & max column count', 'perPage' : 'based on currWidth & colCount', 'totalPages' : 'based on perPage & actualData length', 'currPageNo' : 'used in calculating pageData', 'pageData' : 'based on totalPages & currPageNo' };

Page 87: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

Page 88: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

props = [{ 'src' : '/path/to/image', 'alt' : 'alt text of image', 'title' : 'name of the movie', 'href' : '/path/to/the/movie/details/page', 'cast' : ['array', 'of', 'movie', 'casts'], 'rating' : 'movie rating', 'theater_href' : '/path/to/theater/list' }, {...}, {...}];

state = { 'actualData' : this.props, 'currWidth' : 'calculated current screen width', 'colCount' : 'based on currWidth & max column count', 'perPage' : 'based on currWidth & colCount', 'totalPages' : 'based on perPage & actualData length', 'currPageNo' : 'used in calculating pageData', 'pageData' : 'based on totalPages & currPageNo' };

Page 89: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

Page 90: REACT.JS : Rethinking UI Development Using JavaScript

<MoviePosterContent><MoviePosterList data={ this.state.pageData }>

<PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle,

iHref, iCast } /> <PosterRatingTheater data={ iRating,

itheaterHref } /></PosterItem>

</MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render(<MoviePosterContent data={ data } />, $domNode);

<MoviePosterContent> <MoviePosterList data={ this.state.pageData }> <PosterItem data={ pageData[i] }> <PosterNameCasts data={ iSrc, iAlt, iTitle, iHref, iCast } /> <PosterRatingTheater data={ iRating, itheaterHref } /> </PosterItem> </MoviePosterList>

<Navigation data={ this.state.totalPages, this.state.currPageNo } /></MoviePosterContent>

ReactDOM.render( <MoviePosterContent data={ data } />, $domNode );

props = [{ 'src' : '/path/to/image', 'alt' : 'alt text of image', 'title' : 'name of the movie', 'href' : '/path/to/the/movie/details/page', 'cast' : ['array', 'of', 'movie', 'casts'], 'rating' : 'movie rating', 'theater_href' : '/path/to/theater/list' }, {...}, {...}];

state = { 'actualData' : this.props, 'currWidth' : 'calculated current screen width', 'colCount' : 'based on currWidth & max column count', 'perPage' : 'based on currWidth & colCount', 'totalPages' : 'based on perPage & actualData length', 'currPageNo' : 'used in calculating pageData', 'pageData' : 'based on totalPages & currPageNo' };

Page 91: REACT.JS : Rethinking UI Development Using JavaScript

React v0.14

Page 92: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 93: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 94: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

“This paves the way to writing components that can be shared between the web version of React and React Native. We don’t expect all the code in an app to be shared, but we want to be able to share the components that do behave the same across platforms.”

- React v0.14 release blog

Page 95: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 96: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 97: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 98: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

“...it has become clear that the beauty and essence of React has nothing to do with browsers or the DOM.”

- React v0.14 release blog

Page 99: REACT.JS : Rethinking UI Development Using JavaScript

❖ Enter “React Native”, and also - “React Art”, “React Canvas” and “React Three”

❖ Deprecated: “react-tools” package and “JSXTransform.js”

❖ React namespace split into React and ReactDOM

❖ React keep core functionalities for creating components

❖ ReactDOM for rendering in DOMReact.render(<SayMyName name={ myName } />, document.body);

ReactDOM.render(<SayMyName name={ myName } />, document.body);

Page 100: REACT.JS : Rethinking UI Development Using JavaScript

Flux

Page 101: REACT.JS : Rethinking UI Development Using JavaScript
Page 102: REACT.JS : Rethinking UI Development Using JavaScript

pageData: [ {'Puthiya Niyamam', ...}, {'Maheshinte Prathikaaram', ...}, {'Action Hero Biju', ...}, {'Mastizaade', ...}]

pageData: [ {'Pachakallam', ...}, {'Jalam', ...}, {'Airlift', ...}, {'Kya Kool Hai Hum', ...}]

Page 103: REACT.JS : Rethinking UI Development Using JavaScript
Page 104: REACT.JS : Rethinking UI Development Using JavaScript
Page 105: REACT.JS : Rethinking UI Development Using JavaScript

{ type: 'NEXT_BTN_PRESS' }

{ type: 'PREV_BTN_PRESS' }

{ type: 'JUMP_TO_PAGE', payload: { 'pageNo': 3 }}

{ type: 'WINDOW_RESIZED', payload: { 'newWidth': 600 }}

{ type: 'ADD_TODO', payload: { text: 'Learn ES6' }}

Page 106: REACT.JS : Rethinking UI Development Using JavaScript

{ type: 'NEXT_BTN_PRESS' }

{ type: 'PREV_BTN_PRESS' }

{ type: 'JUMP_TO_PAGE', payload: { 'pageNo': 3 }}

{ type: 'WINDOW_RESIZED', payload: { 'newWidth': 600 }}

{ type: 'ADD_TODO', payload: { text: 'Learn ES6' }}

Page 107: REACT.JS : Rethinking UI Development Using JavaScript

{ type: 'NEXT_BTN_PRESS' }

{ type: 'PREV_BTN_PRESS' }

{ type: 'JUMP_TO_PAGE', payload: { 'pageNo': 3 }}

{ type: 'WINDOW_RESIZED', payload: { 'newWidth': 600 }}

{ type: 'ADD_TODO', payload: { text: 'Learn ES6' }}

Page 108: REACT.JS : Rethinking UI Development Using JavaScript
Page 109: REACT.JS : Rethinking UI Development Using JavaScript

Thank you

Page 110: REACT.JS : Rethinking UI Development Using JavaScript

Vijay DevLead Front-end Engineerhttp://vijaydev.com/