SlideShare a Scribd company logo
REACT 101
Anatoliy Sieryi
Submit PHP 2016
Anatoliy Sieryi
JS Developer
Binary Studio Academy
JS group coach
“Sir are you classified as human?”
“Negative, I am a meat popsicle”
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React
A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES
Declarative
React makes it painless to create
interactive UIs. Design simple views
for each state in your application,
and React will efficiently update and
render just the right components
when your data changes.
Declarative views make your code
more predictable and easier to
debug.
Component-Based
Build encapsulated components that
manage their own state, then
compose them to make complex
UIs.
Since component logic is written in
JavaScript instead of templates, you
can easily pass rich data through
your app and keep state out of the
DOM.
Learn Once, Write
Anywhere
We don't make assumptions about the rest
of your technology stack, so you can
develop new features in React without
rewriting existing code.
React can also render on the server using
Node and power mobile apps using React
Native.
React 101 by Anatoliy Sieryi
React
◉ Vanilla JS
◉ Vanilla JS
◉ Vanilla JS
◉ Vanilla JS. Kinda
◉ Vanilla JS
documentation
Angular 2
◉ Typescript
◉ Batteries Included
◉ DSL
◉ HTML Templates
◉ Typescript
documentation
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
Hello World Component
// React.createElement(component, [props], [...children])
function Hello(props) {
return React.createElement('div', null, `Hello, ${props.name}`);
}
React.createElement(Hello, { name: "World" });
Enter The JSX
function Hello(props) {
return <div>{`Hello, ${props.name}`}</div>;
}
<Hello name="World" />
// <div>Hello, World</div>
JSX example
const element = (
<div>
<h1>Hello!</h1>
<h2>Good to see you here.</h2>
<i className="fa fa-first-order" />
<MyComponent />
</div>
);
Object - Oriented Style
class Hello extends React.Component {
render() {
return <div>{`Hello, ${this.props.name}`}</div>;
}
}
Without ES2015
var Hello = React.createClass({
render: function() {
return <h1>Hello, {this.props.name}</h1>;
}
});
Hello World App / index.html
<html>
<head>
<title>React is Awesome</title>
</head>
<body>
<div id="root"></div>
<script src="app.js"></script>
</body>
</html>
Hello World App / app.js
import React from 'react';
import ReactDOM from 'react-dom';
import Hello from './components/Hello';
ReactDOM.render(
<Hello name="World" />,
document.getElementById('root')
);
import React from 'react';
import ListItem from './ListItem';
export class List extends React.Component {
render() {
return (
<div className="list">
{
this.props.list.map(item =>
<ListItem key={list.id} data="list" />)
}
</div>
);
}
}
import React from 'react';
const warningStyle = {
color: '#ff0000',
fontSize: 'large',
'font-weight': 'bold'
}
export class Warning extends React.Component {
render() {
return (
<div style={warningStyle}>NOOOOOOOO!</div>
);
}
}
export class SomePage extends React.Component {
render() {
return (
{
this.props.isLoggedIn ?
<Welcome />
:
<Forbidden />
}
);
}
}
export class MyButton extends React.Component {
handleClick(e) {
alert(e.target.value);
}
render() {
return (
<input
className="my-button"
type="button"
value="Click me!"
onClick={this.handleClick}
/>
);
}
}
Synthetic Events
boolean bubbles
boolean cancelable
DOMEventTarget currentTarget
boolean defaultPrevented
number eventPhase
boolean isTrusted
DOMEvent nativeEvent
void preventDefault()
boolean isDefaultPrevented()
void stopPropagation()
boolean isPropagationStopped()
DOMEventTarget target
number timeStamp
string type
State
constructor(props) {
super(props);
this.state = {
activeTab: this.props.tabs[0].id,
foo: 'bar'
};
}
onSwitch(id) {
this.setState({ activeTab: id });
}
render() {
const tab = this.props.tabs.find(tab =>
tab.id === this.state.activeTab);
return (
<div className="tabs">
<TabControls
tabs={this.props.tabs}
onSwitch={this.onSwitch.bind(this)}
/>
<TabContent data={tab} />
</div>
);
}
Refs
<input
type="text"
ref={inputNode => this.textInput = inputNode}
/>
scrollToInput() {
this.textInput.scrollIntoView();
}
<input
type="text"
ref="textInput"
/>
focusOnInput() {
this.refs.textInput.focus();
}
React 101 by Anatoliy Sieryi
Component Lifecycle
componentDidMount() {
fetch('data.json').then(res => {
this.setState({
data: res.data
});
});
};
componentWillMount() {
this.interval = setInterval(() => {
console.log('tick')
}, 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
React-Router
import { Router, Route, browserHistory } from 'react-router';
// browserHistory / hashHistory / createMemoryHistory
ReactDOM.render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
<Route path="users" component={Users}>
<Route path="/user/:userId" component={User}/>
</Route>
<Route path="*" component={NoMatch}/>
</Route>
</Router>
), document.getElementById('root'));
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
Basic Configuration
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
const rootReducer = combineReducers({ myReducer, myReducer2 });
const store = createStore(rootReducer);
ReactDOM.render(
<Provider store={store}>
<MyRootComponent />
</Provider>,
document.getElementById('root')
);
Actions
export const DO_A_BARREL_ROLL = 'DO_A_BARREL_ROLL';
export const CHANGE_USER_NAME = 'CHANGE_USER_NAME';
export function doABarrelRoll() {
return {
type: DO_A_BARREL_ROLL
};
}
export function changeUserName(newName) {
return {
type: CHANGE_USER_NAME,
payload: {
newName
}
};
}
Async Actions (redux-thunk)
export function getCustomers(params) {
return (dispatch, getStore) => {
const store = getStore();
api.getCustomers(params).then(res => {
dispatch(populateCustomers(res.data));
});
};
}
export function populateCustomers(customers) {
return {
type: POPULATE_CUSTOMERS,
payload: {
customers
}
};
}
Reducer
import { DO_A_BARREL_ROLL } from './MyPageActions';
const initialState = {
barrelRollsDone: 0
};
export default function myPage(state = initialState, action) {
switch (action.type) {
case DO_A_BARREL_ROLL:
return Object.assign({}, state, {
barrelRollsDone: state.barrelRollsDone + 1
});
default:
return state;
}
}
Container (Smart Component)
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
function mapStateToProps(state) {
return {
myPage: state.myPage
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(Object.assign({}, myPageActions), dispatch)
};
}
export MyComponent;
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
React 101 by Anatoliy Sieryi
Links
React
Redux
The Evolution of Flux Frameworks
Webpack
React boilerplates
How it feels to learn JavaScript in 2016
THANKS!
Any questions?

More Related Content

PDF
Pieter De Baets - An introduction to React Native
PDF
Introduction to React for Frontend Developers
PDF
React Native
PDF
Building cross-platform mobile apps with React Native (Jfokus 2017)
PDF
React & Redux
PPT
Introduction to Vaadin
PDF
Seven Versions of One Web Application
PDF
6 swt programming
Pieter De Baets - An introduction to React Native
Introduction to React for Frontend Developers
React Native
Building cross-platform mobile apps with React Native (Jfokus 2017)
React & Redux
Introduction to Vaadin
Seven Versions of One Web Application
6 swt programming

What's hot (19)

PPTX
Apache Cordova In Action
PDF
Flutter State Management Using GetX.pdf
ODP
Developing Java SWT Applications - A Starter
PDF
Angular2 Development for Java developers
PDF
AngularJS - Services
PPTX
React native by example by Vadim Ruban
PDF
Introduction to Vaadin
 
PPT
Writing and Testing JavaScript-heavy Web 2.0 apps with JSUnit
PPTX
Integrating external products into eclipse
PDF
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
PDF
The Gist of React Native
PPT
JAVA SCRIPT
PPT
JsUnit
PDF
3 Simple Steps to follow to Create React JS Components
PDF
Vaadin Components
PDF
Vaadin Components @ Angular U
PDF
Guice tutorial
PPTX
Single Page Applications with AngularJS 2.0
PPTX
Breaking free from static abuse in test automation frameworks and using Sprin...
Apache Cordova In Action
Flutter State Management Using GetX.pdf
Developing Java SWT Applications - A Starter
Angular2 Development for Java developers
AngularJS - Services
React native by example by Vadim Ruban
Introduction to Vaadin
 
Writing and Testing JavaScript-heavy Web 2.0 apps with JSUnit
Integrating external products into eclipse
How to Implement Basic Angular Routing and Nested Routing With Params in Angu...
The Gist of React Native
JAVA SCRIPT
JsUnit
3 Simple Steps to follow to Create React JS Components
Vaadin Components
Vaadin Components @ Angular U
Guice tutorial
Single Page Applications with AngularJS 2.0
Breaking free from static abuse in test automation frameworks and using Sprin...
Ad

Similar to React 101 by Anatoliy Sieryi (20)

PPTX
React & Redux for noobs
PDF
Lessons from a year of building apps with React Native
PPTX
React native introduction
PDF
React JS and Redux
PDF
React: JSX and Top Level API
PDF
Full Stack React Workshop [CSSC x GDSC]
PPTX
Academy PRO: React JS
PPTX
React outbox
PDF
From User Action to Framework Reaction
PDF
From User Action to Framework Reaction
 
PPTX
JS Fest 2018. Đ˜Đ»ŃŒŃ ИĐČĐ°ĐœĐŸĐČ. ВĐČĐ”ĐŽĐ”ĐœĐžĐ” ĐČ React-Native
PDF
An introduction to React.js
PPTX
Introduction to React and MobX
PPTX
Highload JavaScript Framework without Inheritance
 
PDF
From Backbone to Ember and Back(bone) Again
PPTX
Windows Store app using XAML and C#: Enterprise Product Development
PPTX
React native introduction
PPTX
Combining Angular and React Together
PDF
React Native for multi-platform mobile applications
PDF
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
React & Redux for noobs
Lessons from a year of building apps with React Native
React native introduction
React JS and Redux
React: JSX and Top Level API
Full Stack React Workshop [CSSC x GDSC]
Academy PRO: React JS
React outbox
From User Action to Framework Reaction
From User Action to Framework Reaction
 
JS Fest 2018. Đ˜Đ»ŃŒŃ ИĐČĐ°ĐœĐŸĐČ. ВĐČĐ”ĐŽĐ”ĐœĐžĐ” ĐČ React-Native
An introduction to React.js
Introduction to React and MobX
Highload JavaScript Framework without Inheritance
 
From Backbone to Ember and Back(bone) Again
Windows Store app using XAML and C#: Enterprise Product Development
React native introduction
Combining Angular and React Together
React Native for multi-platform mobile applications
Java Web Programming on Google Cloud Platform [3/3] : Google Web Toolkit
Ad

More from Binary Studio (20)

PPTX
Academy PRO: D3, part 3
PPTX
Academy PRO: D3, part 1
PPTX
Academy PRO: Cryptography 3
PPTX
Academy PRO: Cryptography 1
PPTX
Academy PRO: Advanced React Ecosystem. MobX
PPTX
Academy PRO: Docker. Part 4
PPTX
Academy PRO: Docker. Part 2
PPTX
Academy PRO: Docker. Part 1
PPTX
Binary Studio Academy 2017: JS team project - Orderly
PPTX
Binary Studio Academy 2017: .NET team project - Unicorn
PPTX
Academy PRO: React native - miscellaneous
PPTX
Academy PRO: React native - publish
PPTX
Academy PRO: React native - navigation
PPTX
Academy PRO: React native - building first scenes
PPTX
Academy PRO: React Native - introduction
PPTX
Academy PRO: Push notifications. Denis Beketsky
PPTX
Academy PRO: Docker. Lecture 4
PPTX
Academy PRO: Docker. Lecture 3
PPTX
Academy PRO: Docker. Lecture 2
PPTX
Academy PRO: Docker. Lecture 1
Academy PRO: D3, part 3
Academy PRO: D3, part 1
Academy PRO: Cryptography 3
Academy PRO: Cryptography 1
Academy PRO: Advanced React Ecosystem. MobX
Academy PRO: Docker. Part 4
Academy PRO: Docker. Part 2
Academy PRO: Docker. Part 1
Binary Studio Academy 2017: JS team project - Orderly
Binary Studio Academy 2017: .NET team project - Unicorn
Academy PRO: React native - miscellaneous
Academy PRO: React native - publish
Academy PRO: React native - navigation
Academy PRO: React native - building first scenes
Academy PRO: React Native - introduction
Academy PRO: Push notifications. Denis Beketsky
Academy PRO: Docker. Lecture 4
Academy PRO: Docker. Lecture 3
Academy PRO: Docker. Lecture 2
Academy PRO: Docker. Lecture 1

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administration Chapter 2
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
AI in Product Development-omnex systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Introduction to Artificial Intelligence
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Design an Analysis of Algorithms II-SECS-1021-03
ISO 45001 Occupational Health and Safety Management System
Understanding Forklifts - TECH EHS Solution
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
 
VVF-Customer-Presentation2025-Ver1.9.pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administration Chapter 2
Odoo POS Development Services by CandidRoot Solutions
Operating system designcfffgfgggggggvggggggggg
Which alternative to Crystal Reports is best for small or large businesses.pdf
Odoo Companies in India – Driving Business Transformation.pdf
AI in Product Development-omnex systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PTS Company Brochure 2025 (1).pdf.......
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Introduction to Artificial Intelligence

React 101 by Anatoliy Sieryi

  • 2. Anatoliy Sieryi JS Developer Binary Studio Academy JS group coach “Sir are you classified as human?” “Negative, I am a meat popsicle”
  • 8. React A JAVASCRIPT LIBRARY FOR BUILDING USER INTERFACES Declarative React makes it painless to create interactive UIs. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable and easier to debug. Component-Based Build encapsulated components that manage their own state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep state out of the DOM. Learn Once, Write Anywhere We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using React Native.
  • 10. React ◉ Vanilla JS ◉ Vanilla JS ◉ Vanilla JS ◉ Vanilla JS. Kinda ◉ Vanilla JS documentation Angular 2 ◉ Typescript ◉ Batteries Included ◉ DSL ◉ HTML Templates ◉ Typescript documentation
  • 14. Hello World Component // React.createElement(component, [props], [...children]) function Hello(props) { return React.createElement('div', null, `Hello, ${props.name}`); } React.createElement(Hello, { name: "World" });
  • 15. Enter The JSX function Hello(props) { return <div>{`Hello, ${props.name}`}</div>; } <Hello name="World" /> // <div>Hello, World</div>
  • 16. JSX example const element = ( <div> <h1>Hello!</h1> <h2>Good to see you here.</h2> <i className="fa fa-first-order" /> <MyComponent /> </div> );
  • 17. Object - Oriented Style class Hello extends React.Component { render() { return <div>{`Hello, ${this.props.name}`}</div>; } }
  • 18. Without ES2015 var Hello = React.createClass({ render: function() { return <h1>Hello, {this.props.name}</h1>; } });
  • 19. Hello World App / index.html <html> <head> <title>React is Awesome</title> </head> <body> <div id="root"></div> <script src="app.js"></script> </body> </html>
  • 20. Hello World App / app.js import React from 'react'; import ReactDOM from 'react-dom'; import Hello from './components/Hello'; ReactDOM.render( <Hello name="World" />, document.getElementById('root') );
  • 21. import React from 'react'; import ListItem from './ListItem'; export class List extends React.Component { render() { return ( <div className="list"> { this.props.list.map(item => <ListItem key={list.id} data="list" />) } </div> ); } }
  • 22. import React from 'react'; const warningStyle = { color: '#ff0000', fontSize: 'large', 'font-weight': 'bold' } export class Warning extends React.Component { render() { return ( <div style={warningStyle}>NOOOOOOOO!</div> ); } }
  • 23. export class SomePage extends React.Component { render() { return ( { this.props.isLoggedIn ? <Welcome /> : <Forbidden /> } ); } }
  • 24. export class MyButton extends React.Component { handleClick(e) { alert(e.target.value); } render() { return ( <input className="my-button" type="button" value="Click me!" onClick={this.handleClick} /> ); } }
  • 25. Synthetic Events boolean bubbles boolean cancelable DOMEventTarget currentTarget boolean defaultPrevented number eventPhase boolean isTrusted DOMEvent nativeEvent void preventDefault() boolean isDefaultPrevented() void stopPropagation() boolean isPropagationStopped() DOMEventTarget target number timeStamp string type
  • 26. State constructor(props) { super(props); this.state = { activeTab: this.props.tabs[0].id, foo: 'bar' }; } onSwitch(id) { this.setState({ activeTab: id }); } render() { const tab = this.props.tabs.find(tab => tab.id === this.state.activeTab); return ( <div className="tabs"> <TabControls tabs={this.props.tabs} onSwitch={this.onSwitch.bind(this)} /> <TabContent data={tab} /> </div> ); }
  • 27. Refs <input type="text" ref={inputNode => this.textInput = inputNode} /> scrollToInput() { this.textInput.scrollIntoView(); } <input type="text" ref="textInput" /> focusOnInput() { this.refs.textInput.focus(); }
  • 30. componentDidMount() { fetch('data.json').then(res => { this.setState({ data: res.data }); }); }; componentWillMount() { this.interval = setInterval(() => { console.log('tick') }, 1000); } componentWillUnmount() { clearInterval(this.interval); }
  • 31. React-Router import { Router, Route, browserHistory } from 'react-router'; // browserHistory / hashHistory / createMemoryHistory ReactDOM.render(( <Router history={browserHistory}> <Route path="/" component={App}> <Route path="about" component={About}/> <Route path="users" component={Users}> <Route path="/user/:userId" component={User}/> </Route> <Route path="*" component={NoMatch}/> </Route> </Router> ), document.getElementById('root'));
  • 36. Basic Configuration import { createStore, combineReducers } from 'redux'; import { Provider } from 'react-redux'; const rootReducer = combineReducers({ myReducer, myReducer2 }); const store = createStore(rootReducer); ReactDOM.render( <Provider store={store}> <MyRootComponent /> </Provider>, document.getElementById('root') );
  • 37. Actions export const DO_A_BARREL_ROLL = 'DO_A_BARREL_ROLL'; export const CHANGE_USER_NAME = 'CHANGE_USER_NAME'; export function doABarrelRoll() { return { type: DO_A_BARREL_ROLL }; } export function changeUserName(newName) { return { type: CHANGE_USER_NAME, payload: { newName } }; }
  • 38. Async Actions (redux-thunk) export function getCustomers(params) { return (dispatch, getStore) => { const store = getStore(); api.getCustomers(params).then(res => { dispatch(populateCustomers(res.data)); }); }; } export function populateCustomers(customers) { return { type: POPULATE_CUSTOMERS, payload: { customers } }; }
  • 39. Reducer import { DO_A_BARREL_ROLL } from './MyPageActions'; const initialState = { barrelRollsDone: 0 }; export default function myPage(state = initialState, action) { switch (action.type) { case DO_A_BARREL_ROLL: return Object.assign({}, state, { barrelRollsDone: state.barrelRollsDone + 1 }); default: return state; } }
  • 40. Container (Smart Component) import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; function mapStateToProps(state) { return { myPage: state.myPage }; } function mapDispatchToProps(dispatch) { return { actions: bindActionCreators(Object.assign({}, myPageActions), dispatch) }; } export MyComponent; export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);
  • 52. Links React Redux The Evolution of Flux Frameworks Webpack React boilerplates How it feels to learn JavaScript in 2016