time to react!

26
TIME TO REACT! TIME TO REACT! Radosław Jankiewicz / / @radek_j radekj

Upload: stx-next

Post on 23-Jan-2018

219 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Time to React!

TIME TO REACT!TIME TO REACT!Radosław Jankiewicz / / @radek_j radekj

Page 2: Time to React!

WHO AM IWHO AM IProgramming since 2007Web applicationsPython (mostly)

Page 3: Time to React!

AGENDAAGENDAWhat is React?1. How do you use it?2. Why should you give it a chance?3. Are there any weaknesses of React?4.

Page 4: Time to React!

WHAT IS REACT?WHAT IS REACT?

Page 5: Time to React!

A JAVASCRIPT LIBRARY FORA JAVASCRIPT LIBRARY FORBUILDING USER INTERFACESBUILDING USER INTERFACES

Page 6: Time to React!

1ST PUBLIC RELEASE - MAY 20131ST PUBLIC RELEASE - MAY 2013

Page 7: Time to React!

JUST THE UIJUST THE UILots of people use React as the V in MVC.Since React makes no assumptions aboutthe rest of your technology stack, it's easyto try it out on a small feature in an existingproject.

https://facebook.github.io/react/

Page 8: Time to React!

VIRTUAL DOMVIRTUAL DOMReact abstracts away the DOM from you,giving a simpler programming model andbetter performance.

https://facebook.github.io/react/

Page 9: Time to React!

DATA FLOWDATA FLOWReact implements one-way reactive dataflow which reduces boilerplate and is easierto reason about than traditional databinding.

https://facebook.github.io/react/

Page 10: Time to React!

HOW DO YOU USE REACT?HOW DO YOU USE REACT?

Page 11: Time to React!

COMPONENTSCOMPONENTSvar SimpleComponent = React.createClass({ render: function() {

return ( <div> It is time to react {this.props.today.toTimeString()} !!! </div> ); }});

ReactDOM.render( <SimpleComponent today={new Date()}/>, document.getElementById('example'));

It is time to react 20:24:59 GMT+0100 (CET) !!!

Page 12: Time to React!

JSXJSX<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>

render: function() { return ( <div id="transform">transform text</div> );}

render: function() {return (

React.DOM.div({id: "transform"}, "transform text") );}

Page 13: Time to React!

NESTED COMPONENTSNESTED COMPONENTSvar books = [

{author:'John Smith', title:'Lorem Ipsum'},{author:'Jane Doe', title:'Dolor sit amet'}

];

var ListOfBooks = React.createClass({ render: function() {

return ( <ul> {this.props.books.map(function(book, index) {

return <Book key={index} bookItem={book} />; })} </ul> ); }});var Book = React.createClass({ render: function() {

var bookItem = this.props.bookItem;return <li>{bookItem.title} - {bookItem.author}</li>

}});

Page 14: Time to React!

NESTED COMPONENTSNESTED COMPONENTS<ul data-reactid=".0"> <li data-reactid=".0.$0">John Smith - Lorem Ipsum</li> <li data-reactid=".0.$1">Jane Doe - Dolor sit amet</li></ul>

Page 15: Time to React!

COMPONENT STATECOMPONENT STATEvar Counter = React.createClass({ getInitialState: function() {

return {count: 1}; },

handleClick: function() {this.setState({count: this.state.count + 1});

},

render: function() {return (

<input type="button" onClick={this.handleClick} value={this.state.count} /> ) }});

1

Page 16: Time to React!

VIRTUAL DOMVIRTUAL DOM

Page 17: Time to React!

REACT APIREACT APICOMPONENT SPECIFICATIONSCOMPONENT SPECIFICATIONS

rendergetInitialStategetDefaultPropssetState

Page 18: Time to React!

REACT APIREACT APILIFECYCLE METHODSLIFECYCLE METHODScomponentWillMountcomponentDidMountcomponentWillReceivePropsshouldComponentUpdatecomponentWillUpdatecomponentDidUpdatecomponentWillUnmount

Page 19: Time to React!

LIFECYCLE METHODSLIFECYCLE METHODScomponentWillReceiveProps: function(nextProps) {this.setState({// set something

});}

shouldComponentUpdate: function(nextProps, nextState){// return a boolean valuereturn false;

}

Page 20: Time to React!

FLUXFLUXMVC model might be too complex

https://facebook.github.io/flux

Page 21: Time to React!

FLUXFLUXUnidirectional data flow

https://facebook.github.io/flux

Page 22: Time to React!

WHY SHOULD YOU GIVE IT AWHY SHOULD YOU GIVE IT ACHANCE?CHANCE?

Page 23: Time to React!

BECAUSE IT'S ...BECAUSE IT'S ...FastSimple to learn and easy to useClean and consiceIntegrates easily with other solutions

Page 24: Time to React!

ARE THERE ANY CONS OF REACT?ARE THERE ANY CONS OF REACT?HTML templates in js filesMay be initially hard to switch to for jQuery people

Page 25: Time to React!

QUESTIONS TIMEQUESTIONS TIME

Page 26: Time to React!

SOURCESSOURCEShttps://facebook.github.io/reacthttps://facebook.github.io/flux