Top Banner
React JS Introduction
25
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 JS - Introduction

React JSIntroduction

Page 2: React JS - Introduction

What is React?

Page 3: React JS - Introduction

React is a JavaScript library created by a collaboration of Facebook and Instagram.

Its aim is to allow developers

to create fast user interfaces easily.

Page 4: React JS - Introduction

Big companies use React

Page 5: React JS - Introduction

Facebook

Yahoo!

Airbnb

Instagram

Sony

Page 6: React JS - Introduction

React isn’t a complete framework.

Page 7: React JS - Introduction

React is just the V in MVC.

Page 8: React JS - Introduction

Main aspects of React

Page 9: React JS - Introduction

VIRTUAL DOM REAL DOM

PATCH

virtial dom tree real dom tree

Page 10: React JS - Introduction

SERVER-SIDE RENDERING

BROWSER

REACT

NODE.JS

Updates Markup Data Data

Page Render

HTTP Request

Page 11: React JS - Introduction

ONE-WAY DATA-BINDING MODEL

Page 12: React JS - Introduction

Getting Started with React

Page 13: React JS - Introduction

COMPONENTS

Page 14: React JS - Introduction

COMPONENTS

var MyComponent = React.createClass({ render: function() {

return ( React.createElement("div", null, "Hello World");

)}

});

React.render( <MyComponent/>, document.body

);

Page 15: React JS - Introduction

JSX

Page 16: React JS - Introduction

JSX

var MyComponent = React.createClass({ render: function() {

return ( <h1>Hello World</h1>

)}

});

React.render( <MyComponent/>, document.body

);

Page 17: React JS - Introduction

PROPS

Page 18: React JS - Introduction

PROPS

var MyComponent = React.createClass({ render: function() {

return ( <h1>{this.props.message}</h1>

)}

});

React.render(<MyComponent message="Hello World"/>,document.body

);

Page 19: React JS - Introduction

STATE

Page 20: React JS - Introduction

STATEvar MyComponent = React.createClass({

getInitialState: function() {return {

message: "Hello World" }

},

render: function() { return (

<h1>{this.state.message}</h1> )

} });

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

Page 21: React JS - Introduction

Simple APP with React

Page 22: React JS - Introduction

index.html

<html> <head> <title>Hello World with React</title> </head> <body> <script src="https://fb.me/react-0.12.2.js"></script> <script src="https://fb.me/JSXTransformer-0.12.2.js"></script> <script type="text/jsx" src="hello.jsx"></script> <script type="text/jsx" src="main.jsx"></script> </body></html>

Page 23: React JS - Introduction

hello.jsx

var Hello = React.createClass({render: function() {

return <p>{this.props.message}</p>;}

});

Page 24: React JS - Introduction

main.jsx

React.render(<Hello message="Hello, world!" />,document.body

);