SlideShare a Scribd company logo
INTRODUCTION TO REACT
Presentation by Kiran Abburi
Twitter: @kiran_abburi
HANGOUT ANNOUNCEMENTS
Use Q & A feature to ask questions
MEETUP ANNOUNCEMENTS
Thanks for joining the meetup
Help in finding sponser for meetup location
Active participation on meetup threads
More meetups and hackathons
Feedback
ABOUT ME
Freelance web developer
Currently focusing on react projects
on twitter
Opensource enthusiast
@kiran_abburi
AGENDA
Session 1
Basics of react
Composition
Data Flow
Session 2
JSX
React top level API
React component API and life cycle
Session 3
Building a simple todo app with react
WHAT IS REACT ?
A javascript library for building user interfaces
V in MVC
Simple & Declarative
GETTING STARTED
Starter kit examples
facebook.github.io/react
jsfiddle
STARTER TEMPLATE
<!DOCTYPE html>
<html>
  <head>
    <script src='http://fb.me/react­0.12.2.js'></script>
    <script src='http://fb.me/JSXTransformer­0.12.2.js'></script>
    <script type='text/jsx'>
</script>
  </head>
  <body>
  </body>
</html>
      // React code goes here.
    
HELLO WORLD
var HelloWorld = React.createClass({
  render: function () {
    return <h1>Hello World</h1>
  }
})
React.render(<HelloWorld />, document.body);
REACT COMPONENTS
React is all about building components
We build small reusable components
Compose components to build larger components
­ Page
  ­ Header
    ­ Logo
    ­ Menu
  ­ Content
    ­ SideBar
    ­ MainBody
  ­ Footer
COMPOSITION EXAMPLE
var Page = React.createClass({
  render: function () {
    return (
      <div>
        <Header />
        <Content />
        <Footer />
      </div>
    );
  }
})
var Header = React.createClass({
  render: function () {
    return (
      <div>
        <Logo />
        <Menu />
      </div>
    );
  }
})
Introduction to react
DATA FLOW
Uni-directional data flow
Two types of data: props & state
props are used to pass data and configuration to children
state is the application state of component
PROPS EXAMPLE
var Greet = React.createClass({
  render: function () {
    return <h1> Hello {this.props.name}</h1>
  }
})
React.render(<Greet name='Kiran' />, document.body);
STATE EXAMPLE
var Toggle = React.createClass({
  getInitialState: function () {
    return {flag: false}
  },
  clickHandler: function () {
    this.setState({flag: !this.state.flag})
  },
  render: function () {
    return <button onClick={this.clickHandler}>
              {this.state.flag ? 'on': 'off'}
          </button>;
  }
})
React.render(<Toggle />, document.body);
SESSION1 SUMMARY
We learned
Basics of React
Getting started with react
Building react components
Data flow in react
SESSION 1
Q & A
SESSION 2
JSX
Top level API
Component Specification
Component Lifecycle
JSX
XML-like syntax extension to Javascript
HTML JSX
class className
onclick onClick
style=' ' style={ }
  <div className="header" style={{height: '50px'}}>
    <h1 onClick={this.animateLogo}>Logo</h1> 
    <Menu />
  </div>
JSX EXPRESSIONS
Attribute expressions in a pair of curly braces
Child expressions
<Person name={this.props.name} />
<Header>
{this.props.isLoggedIn ? <Logout /> : <Login />}
</Header>
TOP LEVEL API
React is the entry point to the React library
Mostly used methods
React.createClass
React.render
React.renderToString
React.createClass
Create a component
var Todo = React.createClass({
  // component specification
});
React.render
Render a ReactElement into the DOM
React.render(<Todo />, document.body);
React.render(<Todo />, document.getElementById('todo'));
React.renderToString
Generates html markup for react components
Useful for server-side rendering
Improves SEO
React.renderToString(<Todo />);
COMPONENT SPECIFICATION
render
getInitialState
getDefaultProps
mixins
few more
render
This method is required in all components
render() function should be pure
Should not modify component state
var Todo = React.createClass({
  render: function () {
    return <div></div>
  }
});
getInitialState
Invoked once before the component is mounted.
The return value will be used as the initial value of
this.state
var Todo = React.createClass({
  getInitialState: function () {
    return { todos: [] }
  },
  render: function () {
    return <div></div>
  }
});
getDefaultProps
provides default values for the props that not specified by
the parent component
var Person = React.createClass({
  getDefaultProps: function () {
    return { name: anonymous }
  },
  render: function () {
    return <h1>{this.props.name}</h1>
  }
});
<Person name='kiran' />
<Person />
mixins
to share behavior among multiple components
var FormMixin = {
  submitHandler: function () {
    // submit form
  },
  changeHandler: function () {
    // handle input changes
  }
}
var Form1 = React.createClass({
  mixins: [FormMixin],
  render: function () {
    return <form onSubmit={this.submitHandler}> </form>
  }
})
COMPONENT LIFE CYCLE
hooks to execute code at at specific points in a
component's lifecycle
Most commonly used
componentWillMount
componentDidMount
componentWillUpdate
componentDidUpdate
componentWillUnmount
componentWillMount
Invoked once immediately before the initial rendering
occurs
var Component = React.createClass({
  componentWillMount: function () {
    // code to run before rendering
  },
  render: function () {
    return <div></div>
  }
})
componentDidMount
Invoked once immediately after the initial rendering
occurs
integrate with other JavaScript frameworks
send AJAX requests
var Component = React.createClass({
  componentDidMount: function () {
    // code 
  },
  render: function () {
    return <div></div>
  }
})
componentWillUpdate
Invoked immediately before rendering when new props or
state are being received.
This method is not called for the initial render.
var Component = React.createClass({
  componentWillUpdate: function () {
    // code 
  },
  render: function () {
    return <div></div>
  }
})
componentDidUpdate
Invoked immediately after the component's updates are
flushed to the DOM
var Component = React.createClass({
  componentDidUpdate: function () {
    // code 
  },
  render: function () {
    return <div></div>
  }
})
componentWillUnmount
Invoked immediately before a component is unmounted
from the DOM.
Cleanup like unregistering event listeners
var Component = React.createClass({
  componentWillUnmount: function () {
    // code 
  },
  render: function () {
    return <div></div>
  }
})
SESSION2 SUMMARY
JSX
Top level API
Component Specification
Component Lifecycle
SESSION2
Q & A
SESSION 3
BUILDING A SIMPLE TODO APP
SESSION 3
Q & A

More Related Content

PPTX
reactJS
PPTX
PPTX
Its time to React.js
PPTX
React workshop presentation
PPTX
React js for beginners
PPTX
React js - The Core Concepts
PPTX
Introduction to React JS for beginners
PDF
An introduction to React.js
reactJS
Its time to React.js
React workshop presentation
React js for beginners
React js - The Core Concepts
Introduction to React JS for beginners
An introduction to React.js

What's hot (20)

PPTX
React JS - A quick introduction tutorial
PDF
ReactJS presentation
PPTX
React hooks
PPTX
Introduction to React
PDF
Why Vue.js?
PDF
REST APIs with Spring
PPTX
React.js - The Dawn of Virtual DOM
PPTX
How native is React Native? | React Native vs Native App Development
PPTX
Vue js for beginner
PPTX
Intro to React
PDF
React js
PPTX
[Final] ReactJS presentation
PPTX
React JS: A Secret Preview
PDF
PPTX
React js programming concept
PPTX
A Brief Introduction to React.js
ODP
Introduction to ReactJS
PDF
React and redux
PPTX
ReactJS presentation.pptx
PPTX
Intro to React
React JS - A quick introduction tutorial
ReactJS presentation
React hooks
Introduction to React
Why Vue.js?
REST APIs with Spring
React.js - The Dawn of Virtual DOM
How native is React Native? | React Native vs Native App Development
Vue js for beginner
Intro to React
React js
[Final] ReactJS presentation
React JS: A Secret Preview
React js programming concept
A Brief Introduction to React.js
Introduction to ReactJS
React and redux
ReactJS presentation.pptx
Intro to React
Ad

Similar to Introduction to react (20)

PDF
MeetJS Summit 2016: React.js enlightenment
PPTX
Dyanaimcs of business and economics unit 2
PDF
REACTJS.pdf
PPTX
Presentation on "An Introduction to ReactJS"
PPTX
PDF
Introduction Web Development using ReactJS
PPT
PPTX
React_Introwvq2t2e2ewqtwtq31tef12duction.pptx
PPTX
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
PPTX
React - Start learning today
PDF
Integrating React.js with PHP projects
PDF
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
PPTX
ReactJS_Components_Presentation for freshers
PPTX
Why React's Awesome!
PDF
React & Flux Workshop
PPTX
React + Flux = Joy
PPTX
React JS Workings Exercises Extra Classes
PDF
I Heard React Was Good
MeetJS Summit 2016: React.js enlightenment
Dyanaimcs of business and economics unit 2
REACTJS.pdf
Presentation on "An Introduction to ReactJS"
Introduction Web Development using ReactJS
React_Introwvq2t2e2ewqtwtq31tef12duction.pptx
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React - Start learning today
Integrating React.js with PHP projects
theory-slides-vueh3urh4ur4ur4r44oirj4riu4ri
ReactJS_Components_Presentation for freshers
Why React's Awesome!
React & Flux Workshop
React + Flux = Joy
React JS Workings Exercises Extra Classes
I Heard React Was Good
Ad

Recently uploaded (20)

PDF
Understanding Forklifts - TECH EHS Solution
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PPTX
Materi_Pemrograman_Komputer-Looping.pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
System and Network Administraation Chapter 3
PPT
Introduction Database Management System for Course Database
PDF
A REACT POMODORO TIMER WEB APPLICATION.pdf
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
top salesforce developer skills in 2025.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
AI in Product Development-omnex systems
PPTX
Presentation of Computer CLASS 2 .pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
How to Confidently Manage Project Budgets
PPTX
AIRLINE PRICE API | FLIGHT API COST |
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Understanding Forklifts - TECH EHS Solution
Best Practices for Rolling Out Competency Management Software.pdf
Materi_Pemrograman_Komputer-Looping.pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
ISO 45001 Occupational Health and Safety Management System
System and Network Administraation Chapter 3
Introduction Database Management System for Course Database
A REACT POMODORO TIMER WEB APPLICATION.pdf
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Upgrade and Innovation Strategies for SAP ERP Customers
top salesforce developer skills in 2025.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
AI in Product Development-omnex systems
Presentation of Computer CLASS 2 .pptx
How Creative Agencies Leverage Project Management Software.pdf
How to Confidently Manage Project Budgets
AIRLINE PRICE API | FLIGHT API COST |
Which alternative to Crystal Reports is best for small or large businesses.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...

Introduction to react