+ - 0:00:00
Notes for current slide
Notes for next slide

Front-end training

ReactJS

1 / 12

About

  • A javascript library for building user interfaces
  • Made by Facebook's and Instagram's teams
  • ~50k stars on github
  • HTML-like syntax (JSX) in javascript files
  • Very easy to learn and understand the logic behind main approaches
2 / 12

Key Points

  • UI components are the cohesive units
  • UI description and UI logic are tightly coupled
  • Re-render everything on every update
  • Virtual DOM and Synthetic Events
3 / 12

Virtual DOM

  1. Create lightweight description of component UI
  2. Diff it with the old one
  3. Compute minimal set of changes to apply to the DOM
  4. Batch execute all updates
4 / 12

Hello World!

...
<div id="app" />
...
var HelloMessage = React.createClass({
render: function() {
return <div>Hello World</div>;
}
});
ReactDOM.render(
<HelloMessage />,
document.getElementById('app')
);
5 / 12

Component Composition

var HomePage = React.createClass({
render: function() {
return (
<div>
<Header />
<SearchBar />
<BearList />
</div>
);
}
});
6 / 12

Data Flow

  • Parent-to-Child

    • Data can be passed to children as properties and available as this.props
    • Properties are immutable
  • Child-to-Parent

    • Event handlers (callbacks) can be passed as properties
...
onSearch: function(keyword) {
alert(keyword)
},
render: function() {
return (
<Header title="Hello World" />
<SearchBar onSearch={this.onSearch} />
);
}
...
7 / 12

Data Flow cont.

// Header.js
...
propTypes: {
title: React.PropTypes.string
},
render: function() {
return <h1>{this.props.title}</h1>;
}
...
// SearchBar.js
...
onChange: function(e) {
this.props.onSearch(e.target.value);
},
render: function() {
return (
<input type="text" onChange={this.onChange} />;
);
}
...
8 / 12

State

State is mutable and a private data-set of a component

var HomePage = React.createClass({
getInitialState: function() {
return { beers: [] }
},
onSearch: function(q) {
this.props.service.findByKey(q).then(function(items) {
this.setState({ beers: items });
}.bind(this));
},
render: function() {
return (
<div>
<SearchBar onSearch={this.onSearch} />
<BeerList items={this.state.beers} />
</div>
);
}
});
9 / 12

Component Lifecycle

component lifecycle

10 / 12

Thank You!

Questions?

12 / 12

About

  • A javascript library for building user interfaces
  • Made by Facebook's and Instagram's teams
  • ~50k stars on github
  • HTML-like syntax (JSX) in javascript files
  • Very easy to learn and understand the logic behind main approaches
2 / 12
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow