Top Banner
React Js @panbhag
42

Reactjs workshop

Jul 21, 2015

Download

Technology

Pankaj Bhageria
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Reactjs workshop

React Js

@panbhag

Page 2: Reactjs workshop

What is it?

Page 3: Reactjs workshop

A JavaScript Library to build user interfaces

Page 4: Reactjs workshop

Ease of Development Usability

Traditional Web App Easy Bad

Page 5: Reactjs workshop

Ease of Development Usability

SPA(angular/backbone) Complex Good

Page 6: Reactjs workshop

Ease of Development Usability

React Easy Good

Page 7: Reactjs workshop

Lets start codingWe will discuss what is react,why react later

Page 8: Reactjs workshop

Hello World

Page 9: Reactjs workshop

HTML document

Page 10: Reactjs workshop

React.render(reactElement,container)

Page 11: Reactjs workshop

React.createElement(name,options,children)

Page 12: Reactjs workshop

Hello World in JSX

Page 13: Reactjs workshop

JSXJavaScript syntax extension that looks similar to XML/

HTML

Page 14: Reactjs workshop

Why JSX

• Familiar

• Easier to read and write tree like structures in XML format

Page 15: Reactjs workshop

<h1>Hello world</h1>

React.createElement("h1", null, "Hello world Hi")

JSX to Javascript

Page 16: Reactjs workshop

jsx vs HTML

• className instead of class attribute

• html-for instead of for attribute in label

• for style, convert all css hyphen separated style names to camel cased names and pass it as a json object

Page 17: Reactjs workshop

ComponentsReact is all about components

Page 18: Reactjs workshop

render function should return a react element

options = {render:function,…. }

React.createClass(options)

Page 19: Reactjs workshop

Hello World Component

Page 20: Reactjs workshop

Header component accepting children

Page 21: Reactjs workshop

Header component accepting attribute for optional underline

Page 22: Reactjs workshop

Composition: Hello component from Header Component

Page 23: Reactjs workshop

Events: Add a click event to the Hello component

Page 24: Reactjs workshop

–Johnny Appleseed

State: Add a counter for number of times clicked

Page 25: Reactjs workshop

Whenever state changes the entire component renders again

Page 26: Reactjs workshop

Shadow Dom

Page 27: Reactjs workshop

React first renders the component in shadow dom and does the diff with the previous version and updates only what changed to the browser

Page 28: Reactjs workshop

State vs props

Page 29: Reactjs workshop

Component Life Cycle

Page 30: Reactjs workshop

First Component use

• getDefaultProps

• getInitialState

• componentWillMount

• render

• componentDidMount

Page 31: Reactjs workshop

Next Component Use

• getInitialState

• componentWillMount

• render

• componentDidMount

Page 32: Reactjs workshop

Component Update

• componentWillReceiveProps

• shouldComponentUpdate

• componentWillUpdate

• render

• componentDidUpdate

Page 33: Reactjs workshop

Component Removal

• componentWillUnmount

Page 34: Reactjs workshop

Todo App

Page 35: Reactjs workshop

Flux Architecture

Page 36: Reactjs workshop
Page 37: Reactjs workshop

ReFlux Architecture

Page 38: Reactjs workshop
Page 39: Reactjs workshop

Todo Refulx

Page 40: Reactjs workshop

Todo Immutable

Page 41: Reactjs workshop

Immutable data is one which cannot be modified

Page 42: Reactjs workshop

Todo Cortex