Top Banner
React
39
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: React

React

Page 2: React

import React from 'react';

React.render(<p>Hello</p>, document.body);

Page 3: React
Page 5: React
Page 6: React

@7sheepnet 1

1 https://twitter.com/sangramvajre/status/582740689001172992

Page 7: React
Page 8: React

React

Page 9: React
Page 10: React

#1Re-rendering

Page 11: React
Page 12: React

Data changing over time is theroot of all evil.

Page 13: React

Re-renderingEvery place data is displayed is guaranteed to be up-to-date.

Page 14: React

Re-renderingNo magical data binding.

Page 15: React

Re-renderingNo model dirty checking.

Page 16: React

Re-renderingNo more explicit DOM operations- everything is declarative.

Page 17: React

Re-renderingBuilt in - Virtual DOM!

Page 18: React

#2Components

Page 19: React

Frameworks

— Controllers

— Directives

— Templates

— Global Event Listeners

— Models

— View Models

Page 20: React

React

— Controllers

— Directives

— Templates

— Global Event Listeners

— Models

— View Models

Page 21: React

?— Seperation of concerns

— MVC

Page 22: React

Everything is a component

Page 23: React
Page 24: React
Page 25: React
Page 26: React
Page 27: React
Page 28: React

Components

— composable

— resuable

— maintainable

— testable

Page 29: React

#3Single source of truth

Page 30: React

Data flow

— no framework: any component can communicate with any other component

— Backbone: pubsub

— Angular & Ember: two-way binding

— React: one-way data flow

Page 31: React

class CartItem extends React.Component { render() { return ( <div> <Button text="Remove" /> </div> ) }}

class Button extends ReactComponent { render() { return ( <button>{this.props.text}</button> ) }}

Page 32: React

Props

— passed from parents to their childs

— immutable

Page 33: React

class Button extends React.Component { render() { this.props.text = 'bar' // not working

return ( <button>{this.props.text}</button> ) }}

Page 34: React

State

— internal only

— mutable

— can be passed as props

Page 35: React

class CartItem extends React.Component { render() { this.setState({ text: 'Remove this item' })

return ( <div> <Button text={this.state.text} /> </div> ) }}

Page 36: React

Events

— flow up from components

Page 37: React

class CartItem extends React.Component { removeItem() { /* ... */ },

render() { return ( <div> <Button text="Remove" onClick={this.removeItem} /> </div> ) }}

class Button extends React.Component { render() { return ( <button onClick={this.props.onClick}>{this.props.text}</button> ) }}

Page 38: React

Read more— @reactjs

— https://egghead.io

— https://facebook.github.io/react/index.html

— http://www.slideshare.net/AndrewHull/react-js-and-why-its-awesome

— http://www.slideshare.net/KamleshKumarSingh/react-mit

Page 39: React

Thx!