REACT JS
INTRODUCTION
CONTENT
• Introduction React JS and JSX
• Component, State, Props.
• Life Cycle of Component
• Pros & Cos
• Demonstration
WHAT IS REACT?
• A JavaScript Library For Building User Interfaces
• Renders your UI and responds to events.
• It also uses the concept called Virtual DOM, creates an in-memory data structure
cache, enumerates the resulting differences, and then updates the browser’s
displayed DOM efficiently.
• One of the unique features of React.js is not only it can perform on the client side, but
it can also be rendered on the server side, and they can work together interoperably.
Angular has
• modules
• controllers
• directives
• scopes
• templating
• linking functions
• filters
• dependency injection
WHAT IS REACT?
Angular has JUST COMPONENT
• modules
• controllers
• directives
• scopes
• templating
• linking functions
• filters
• dependency injection
WHAT IS REACT?
#2 Single Source of Truth
MVC proposes that your Model
is the single source of truth—
 all state lives there. Views
are derived from the Model,
and must be kept in sync.
When the Model changes, so
does the View.
WHAT IS REACT?
#2 Single Source of Truth
MVC proposes that your Model
is the single source of truth—
 all state lives there. Views
are derived from the Model,
and must be kept in sync.
When the Model changes, so
does the View.
WHAT IS REACT?
I AM DOUBLE-EDGED SWORD
#2 Single Source of Truth
MVC proposes that your Model
is the single source of truth—
 all state lives there. Views
are derived from the Model,
and must be kept in sync.
When the Model changes, so
does the View.
WHAT IS REACT?
I AM DOUBLE-EDGED SWORD
Only render when state
changed
WHAT IS REACT? – VIRTUAL DOM
• Manipulate DOM is high cost.
• React first assembles the entire structure
of your app in-memory, using those
objects. Then, it converts that structure
into actual DOM nodes and inserts them
in your browser’s DOM.
WHAT IS REACT? – VIRTUAL DOM
<script>
var helloEl = React.createElement(
'div',
{ className: 'hello' },
'Hello, world!‘
);
React.render(helloEl,document.body);
</script>
JSX
• JSX = Javascript + XML.
const element = <h1>Hello, world!</h1>;
JSX
<script>
var helloEl = React.createElement('div', { className: 'hello' }, 'Hello,
world!');
React.render(
helloEl,
document.body
);
</script>
<script type="text/jsx">
var helloEl = <div className: "hello">Hello, world!</div>;
React.render(
helloEl,
document.body
);
</script>
JSX
<script>
var helloEl = React.createElement('div', { className: 'hello' }, 'Hello,
world!');
React.render(
helloEl,
document.body
);
</script>
<script type="text/jsx">
var helloEl = <div className: "hello">Hello, world!</div>;
React.render(
helloEl,
document.body
);
</script>
COMPONENT
• Components let you split the UI into independent, reusable pieces, and think about
each piece in isolation.
• Conceptually, components are like JavaScript functions. They accept arbitrary inputs
(called "props") and return React elements describing what should appear on the
screen.
[Final] ReactJS presentation
[Final] ReactJS presentation
COMPONENT
class TodoInput extends React.Component {
render() {
return (
<div className="form-inline">
<input className="form-control" type="text" value={this.state.content}
onChange={this.updateState}/>
</div>
);
}
}
COMPONENT - PROPS
• Props is what you pass into the Component via attributes.
• Props is the only way to input data. (Or you can use Redux).
• Props are immutable.
• Container component will define data that can be changed
• Child Component will received data from parent component via props.
COMPONENT - PROPS
import React from 'react';
class App extends React.Component {
render() {
return (
<div>
<h1>{this.props.headerProp}</h1>
<h2>{this.props.contentProp}</h2>
</div>
);
}
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.jsx';
ReactDOM.render(
<App headerProp="Header from props..."
contentProp="Content from props..."/>,
document.getElementById('app')
);
export default App;
COMPONENT - STATE
• Private data of component
• When change -> Re-render Component
• Can’t read from outside Component
COMPONENT - STATE
class TodoInput extends React.Component {
constructor(props) {
super(props); //Call this function because 'this' is not allowed before super().
this.state = {
content: ''
};
this.addTodo = this.addTodo.bind(this);
}
updateState(e) {
this.setState({content: e.target.value});
}
addTodo() {
// We of course not declare onSave function of this component at parent component
// Refer to: Body.jsx for more information
// We declare this onSave at mapDispatchToProps function
this.props.onSave.call(this, this.state.content, this.props.todo && this.props.todo.id || null);
this.setState({
content: ''
})
}
render() {
return (
<div className="form-inline">
<div className="form-group">
<input className="form-control" type="text" value={this.state.content} onChange={this.updateState}/>
</div>
</div>
);
}
}
class TodoInput extends React.Component {
constructor(props) {
super(props); //Call this function because 'this' is not allowed before super().
this.state = {
content: ''
};
this.addTodo = this.addTodo.bind(this);
}
updateState(e) {
this.setState({content: e.target.value});
}
addTodo() {
// We of course not declare onSave function of this component at parent component
// Refer to: Body.jsx for more information
// We declare this onSave at mapDispatchToProps function
this.props.onSave.call(this, this.state.content, this.props.todo && this.props.todo.id || null);
this.setState({
content: ''
})
}
render() {
return (
<div className="form-inline">
<div className="form-group">
<input className="form-control" type="text" value={this.state.content} onChange={this.updateState}/>
</div>
</div>
);
}
}
REACT COMPONENT LIFECYCLE
• React enables to create components by invoking the React.createClass() method
which expects a render method and triggers a lifecycle that can be hooked into via a
number of so called lifecycle methods.
• This short article should shed light into all the applicable functions.
• Understanding the component lifecycle will enable you to perform certain actions
when a component is created or destroyed. Further more it gives you the
opportunity to decide if a component should be updated in the first place and to
react to props or state changes accordingly.
THE LIFECYCLE -
INITIALIZATION
• Occurs when the component is created.
var Greeting = React.createClass({
propTypes: {
name: React.PropTypes.string
},
getDefaultProps: function () {
return {
name: 'Mary'
};
},
getInitialState: function () {
return {
helloSentence: 'Hello'
}
}
// ...
});
THE LIFECYCLE -
INITIALIZATION
• getDefaultProps and getInitialState not exists when
define Component as Class ES6.
Greeting.defaultProps = {
name: 'Mary'
};
constructor(props){
super(props);
this.state = {
name: 'Mary'
}
}
THE LIFECYCLE -
INITIALIZATION
• Inside ComponentWillMount, setting state won’t
trigger re-render whole component.
• We CAN NOT modify state in render method.
• DOM Manipulation is only permitted inside
componentDidMount method.
THE LIFECYCLE -
STATE CHANGES
• Occur when state is changed (via this.setState(..))
except inside componentWillMount methods
shouldComponentUpdate: function(nextProps, nextState){
// return a boolean value
return true;
}
• shouldComponentUpdate returning false results in
followed methods won’t be triggerd also.
• shouldComponentUpdate won’t triggered in the
initial phase or when call forceUpdate().
• Current State of Component DID NOT have new
value,
THE LIFECYCLE -
PROPS CHANGES
• Occurs when data passed from parent component to
child component changed (via props).
• Changing states in ComponentWillReceiveProps DID
NOT trigger re-render component.
componentWillReceiveProps: function(nextProps)
{
this.setState({
// set something
});
}
Props Change  componentWillReceiveProps trigged
Props Change  componentWillReceiveProps trigged
NOT
THE LIFECYCLE -
UNMOUNTING
• Used to clean up data
PROS & COS OF REACT.JS
THE GOOD POINTS:
• React.js is extremely efficient
- Virtual DOM
• It makes writing Javascript easier
- React.js uses a special syntax called JSX
• It gives you out-of-the-box developer
tools
- React.js chrome extension
• It’s awesome for SEO
- Server rendering
• UI Test Cases
THE BAD:
• React.js is only a view layer.
• There is a learning curve for beginners
who are new to web development.
• Library size. (~ Angular)
Why you should use React.js:
• React.js works great for teams, strongly enforcing UI and workflow patterns.
• The user interface code is readable and maintainable.
• Componentized UI is the future of web development, and you need to start doing it
now.
• And also, there is now a lot of demand for developers with ReactJS experience.
Why you should NOT use React.js:
• Slow you down tremendously at the start.
• You will reinvent a lot of wheels.
• Flux/Redux
• React Native
OUR NEXT STEPS
REFERENCES
• https://firstdoit.com/how-i-learned-to-stop-worrying-and-love-react-
4e22b0bb6c2a#.vt2mjxu6s
• https://offroadcode.com/journal/news/reactjs-whats-it-all-about/
• http://sixrevisions.com/javascript/why-i-ditched-angular-for-react/
• https://github.com/hpphat92/my-todo-reactjs
• https://hpphat.wordpress.com/category/web-dev/react/
• http://blog.andrewray.me/reactjs-for-stupid-people/
• 192.168.1.240sharePhat.HongReactjs
[Final] ReactJS presentation
[Final] ReactJS presentation

More Related Content

PPTX
Introduction to React JS
PPTX
React JS - A quick introduction tutorial
PDF
React js
PPTX
Introduction to React JS for beginners
PPTX
Introduction to React JS for beginners | Namespace IT
PDF
ReactJS presentation
PPTX
Reactjs
Introduction to React JS
React JS - A quick introduction tutorial
React js
Introduction to React JS for beginners
Introduction to React JS for beginners | Namespace IT
ReactJS presentation
Reactjs

What's hot (20)

PPTX
reactJS
PDF
WEB DEVELOPMENT USING REACT JS
PPTX
React js programming concept
PPTX
ReactJS presentation.pptx
PPTX
Introduction to react_js
PPTX
Intro to React
PPTX
React workshop
PPTX
React js
PPTX
React + Redux Introduction
ODP
Introduction to ReactJS
PDF
React JS - Introduction
PPTX
React js for beginners
PDF
Understanding react hooks
PPTX
React js - The Core Concepts
PPTX
React workshop presentation
PPTX
React hooks
PDF
An introduction to React.js
PPTX
React JS: A Secret Preview
PDF
Basics of React Hooks.pptx.pdf
PDF
React and redux
reactJS
WEB DEVELOPMENT USING REACT JS
React js programming concept
ReactJS presentation.pptx
Introduction to react_js
Intro to React
React workshop
React js
React + Redux Introduction
Introduction to ReactJS
React JS - Introduction
React js for beginners
Understanding react hooks
React js - The Core Concepts
React workshop presentation
React hooks
An introduction to React.js
React JS: A Secret Preview
Basics of React Hooks.pptx.pdf
React and redux
Ad

Viewers also liked (10)

PPT
Kuali Identity Management - Introduction And Implementation Options
PDF
React Component Library Design @WalmartLabs
PPTX
React js - Component specs and lifecycle
PDF
Using redux
PDF
Building React Applications with Redux
PPTX
Intro to React
PDF
React – Structure Container Component In Meteor
PPTX
Rethinking Best Practices
PDF
React JS and why it's awesome
PDF
learning react
Kuali Identity Management - Introduction And Implementation Options
React Component Library Design @WalmartLabs
React js - Component specs and lifecycle
Using redux
Building React Applications with Redux
Intro to React
React – Structure Container Component In Meteor
Rethinking Best Practices
React JS and why it's awesome
learning react
Ad

Similar to [Final] ReactJS presentation (20)

PDF
Introduction Web Development using ReactJS
PPTX
ReactJS (1)
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
PPTX
2.React tttttttttttttttttttttttttttttttt
PDF
Getting Started with React, When You’re an Angular Developer
PDF
Tech Talk on ReactJS
PPTX
React Workshop: Core concepts of react
PDF
Welcome to React & Flux !
PPTX
Introduction to React JS.pptx
PPTX
Introduction to ReactJS UI Web Dev .pptx
PPTX
class based component.pptx
PPTX
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
PPTX
Presentation on "An Introduction to ReactJS"
PDF
Workshop 19: ReactJS Introduction
PPTX
Intro to React.js
PPTX
Dyanaimcs of business and economics unit 2
PPTX
Getting started with react &amp; redux
PPTX
React.js - The Dawn of Virtual DOM
PDF
React && React Native workshop
PPTX
React - Start learning today
Introduction Web Development using ReactJS
ReactJS (1)
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
2.React tttttttttttttttttttttttttttttttt
Getting Started with React, When You’re an Angular Developer
Tech Talk on ReactJS
React Workshop: Core concepts of react
Welcome to React & Flux !
Introduction to React JS.pptx
Introduction to ReactJS UI Web Dev .pptx
class based component.pptx
unit 2 React js.pptxdgdgdgdgdgdgdgdgdsgdgdg
Presentation on "An Introduction to ReactJS"
Workshop 19: ReactJS Introduction
Intro to React.js
Dyanaimcs of business and economics unit 2
Getting started with react &amp; redux
React.js - The Dawn of Virtual DOM
React && React Native workshop
React - Start learning today

[Final] ReactJS presentation

  • 2. CONTENT • Introduction React JS and JSX • Component, State, Props. • Life Cycle of Component • Pros & Cos • Demonstration
  • 3. WHAT IS REACT? • A JavaScript Library For Building User Interfaces • Renders your UI and responds to events. • It also uses the concept called Virtual DOM, creates an in-memory data structure cache, enumerates the resulting differences, and then updates the browser’s displayed DOM efficiently. • One of the unique features of React.js is not only it can perform on the client side, but it can also be rendered on the server side, and they can work together interoperably.
  • 4. Angular has • modules • controllers • directives • scopes • templating • linking functions • filters • dependency injection WHAT IS REACT?
  • 5. Angular has JUST COMPONENT • modules • controllers • directives • scopes • templating • linking functions • filters • dependency injection WHAT IS REACT?
  • 6. #2 Single Source of Truth MVC proposes that your Model is the single source of truth—  all state lives there. Views are derived from the Model, and must be kept in sync. When the Model changes, so does the View. WHAT IS REACT?
  • 7. #2 Single Source of Truth MVC proposes that your Model is the single source of truth—  all state lives there. Views are derived from the Model, and must be kept in sync. When the Model changes, so does the View. WHAT IS REACT? I AM DOUBLE-EDGED SWORD
  • 8. #2 Single Source of Truth MVC proposes that your Model is the single source of truth—  all state lives there. Views are derived from the Model, and must be kept in sync. When the Model changes, so does the View. WHAT IS REACT? I AM DOUBLE-EDGED SWORD Only render when state changed
  • 9. WHAT IS REACT? – VIRTUAL DOM • Manipulate DOM is high cost. • React first assembles the entire structure of your app in-memory, using those objects. Then, it converts that structure into actual DOM nodes and inserts them in your browser’s DOM.
  • 10. WHAT IS REACT? – VIRTUAL DOM <script> var helloEl = React.createElement( 'div', { className: 'hello' }, 'Hello, world!‘ ); React.render(helloEl,document.body); </script>
  • 11. JSX • JSX = Javascript + XML. const element = <h1>Hello, world!</h1>;
  • 12. JSX <script> var helloEl = React.createElement('div', { className: 'hello' }, 'Hello, world!'); React.render( helloEl, document.body ); </script> <script type="text/jsx"> var helloEl = <div className: "hello">Hello, world!</div>; React.render( helloEl, document.body ); </script>
  • 13. JSX <script> var helloEl = React.createElement('div', { className: 'hello' }, 'Hello, world!'); React.render( helloEl, document.body ); </script> <script type="text/jsx"> var helloEl = <div className: "hello">Hello, world!</div>; React.render( helloEl, document.body ); </script>
  • 14. COMPONENT • Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. • Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called "props") and return React elements describing what should appear on the screen.
  • 17. COMPONENT class TodoInput extends React.Component { render() { return ( <div className="form-inline"> <input className="form-control" type="text" value={this.state.content} onChange={this.updateState}/> </div> ); } }
  • 18. COMPONENT - PROPS • Props is what you pass into the Component via attributes. • Props is the only way to input data. (Or you can use Redux). • Props are immutable. • Container component will define data that can be changed • Child Component will received data from parent component via props.
  • 19. COMPONENT - PROPS import React from 'react'; class App extends React.Component { render() { return ( <div> <h1>{this.props.headerProp}</h1> <h2>{this.props.contentProp}</h2> </div> ); } } export default App; import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.jsx'; ReactDOM.render( <App headerProp="Header from props..." contentProp="Content from props..."/>, document.getElementById('app') ); export default App;
  • 20. COMPONENT - STATE • Private data of component • When change -> Re-render Component • Can’t read from outside Component
  • 21. COMPONENT - STATE class TodoInput extends React.Component { constructor(props) { super(props); //Call this function because 'this' is not allowed before super(). this.state = { content: '' }; this.addTodo = this.addTodo.bind(this); } updateState(e) { this.setState({content: e.target.value}); } addTodo() { // We of course not declare onSave function of this component at parent component // Refer to: Body.jsx for more information // We declare this onSave at mapDispatchToProps function this.props.onSave.call(this, this.state.content, this.props.todo && this.props.todo.id || null); this.setState({ content: '' }) } render() { return ( <div className="form-inline"> <div className="form-group"> <input className="form-control" type="text" value={this.state.content} onChange={this.updateState}/> </div> </div> ); } } class TodoInput extends React.Component { constructor(props) { super(props); //Call this function because 'this' is not allowed before super(). this.state = { content: '' }; this.addTodo = this.addTodo.bind(this); } updateState(e) { this.setState({content: e.target.value}); } addTodo() { // We of course not declare onSave function of this component at parent component // Refer to: Body.jsx for more information // We declare this onSave at mapDispatchToProps function this.props.onSave.call(this, this.state.content, this.props.todo && this.props.todo.id || null); this.setState({ content: '' }) } render() { return ( <div className="form-inline"> <div className="form-group"> <input className="form-control" type="text" value={this.state.content} onChange={this.updateState}/> </div> </div> ); } }
  • 22. REACT COMPONENT LIFECYCLE • React enables to create components by invoking the React.createClass() method which expects a render method and triggers a lifecycle that can be hooked into via a number of so called lifecycle methods. • This short article should shed light into all the applicable functions. • Understanding the component lifecycle will enable you to perform certain actions when a component is created or destroyed. Further more it gives you the opportunity to decide if a component should be updated in the first place and to react to props or state changes accordingly.
  • 23. THE LIFECYCLE - INITIALIZATION • Occurs when the component is created. var Greeting = React.createClass({ propTypes: { name: React.PropTypes.string }, getDefaultProps: function () { return { name: 'Mary' }; }, getInitialState: function () { return { helloSentence: 'Hello' } } // ... });
  • 24. THE LIFECYCLE - INITIALIZATION • getDefaultProps and getInitialState not exists when define Component as Class ES6. Greeting.defaultProps = { name: 'Mary' }; constructor(props){ super(props); this.state = { name: 'Mary' } }
  • 25. THE LIFECYCLE - INITIALIZATION • Inside ComponentWillMount, setting state won’t trigger re-render whole component. • We CAN NOT modify state in render method. • DOM Manipulation is only permitted inside componentDidMount method.
  • 26. THE LIFECYCLE - STATE CHANGES • Occur when state is changed (via this.setState(..)) except inside componentWillMount methods shouldComponentUpdate: function(nextProps, nextState){ // return a boolean value return true; } • shouldComponentUpdate returning false results in followed methods won’t be triggerd also. • shouldComponentUpdate won’t triggered in the initial phase or when call forceUpdate(). • Current State of Component DID NOT have new value,
  • 27. THE LIFECYCLE - PROPS CHANGES • Occurs when data passed from parent component to child component changed (via props). • Changing states in ComponentWillReceiveProps DID NOT trigger re-render component. componentWillReceiveProps: function(nextProps) { this.setState({ // set something }); } Props Change  componentWillReceiveProps trigged Props Change  componentWillReceiveProps trigged NOT
  • 28. THE LIFECYCLE - UNMOUNTING • Used to clean up data
  • 29. PROS & COS OF REACT.JS THE GOOD POINTS: • React.js is extremely efficient - Virtual DOM • It makes writing Javascript easier - React.js uses a special syntax called JSX • It gives you out-of-the-box developer tools - React.js chrome extension • It’s awesome for SEO - Server rendering • UI Test Cases THE BAD: • React.js is only a view layer. • There is a learning curve for beginners who are new to web development. • Library size. (~ Angular)
  • 30. Why you should use React.js: • React.js works great for teams, strongly enforcing UI and workflow patterns. • The user interface code is readable and maintainable. • Componentized UI is the future of web development, and you need to start doing it now. • And also, there is now a lot of demand for developers with ReactJS experience.
  • 31. Why you should NOT use React.js: • Slow you down tremendously at the start. • You will reinvent a lot of wheels.
  • 32. • Flux/Redux • React Native OUR NEXT STEPS
  • 33. REFERENCES • https://firstdoit.com/how-i-learned-to-stop-worrying-and-love-react- 4e22b0bb6c2a#.vt2mjxu6s • https://offroadcode.com/journal/news/reactjs-whats-it-all-about/ • http://sixrevisions.com/javascript/why-i-ditched-angular-for-react/ • https://github.com/hpphat92/my-todo-reactjs • https://hpphat.wordpress.com/category/web-dev/react/ • http://blog.andrewray.me/reactjs-for-stupid-people/ • 192.168.1.240sharePhat.HongReactjs