React manner using 1-

 

Understanding React

React is a user interface for building JAVASCRIPT library. (JQuery is )

React mainly used to build the UI , many people think React is MVC in V (view). mvvm

React originated in Facebook internal project.

 

grammar:

React use JSX (JS xml) to replace the conventional JavaScript  

JSX is javascript syntactic sugar

We do not necessarily use the JSX , but it has the following advantages:

1 , JSX execute faster, because it is compiled into JavaScript has been optimized code.

2 , it is type-safe, you can find errors during compilation.

3 , using JSX writing templates easier and faster.

 

jsx template
 
const = TEMP < h1 of > Hello </ h1 of > ; 

Let A = < div > 

< h1 of > </ h1 of > < H2 > </ H2 >           outside must be wrapped in a sub-tag root label 

</ div >

 

 

 

Use React in two ways:

1, directly in the html using-side script manner introduction Babel , REACT , reac_dom JS file

Inefficient, due to the real-time conversion

 

2, installation of scaffolding, in the manner of projects using react

Package.json is dependent recording project download package

 

installation steps:

Installation create-react-app

cnpm instal -g create-react-app // global installed scaffolding

 

Create a project

create-react-app app ( project name )  

Startup project

cd app

npm start //yarn start

 

Installation cnpm

npm install -g cnpm

 

For use someone else's project, is generally not the nodelmodel ( put the project depends folder ) it to you (because too much), so first of all depend on good first download the project, through npm install automatically according to packge.json file the record downloading dependencies, and then you can start the project.

 

 

There are two ways of declaring components:

 

1, the function declaration

Function name must be capitalized, it represents a component, or the browser considered html element

 

The first parameter is a template ( or a react element ) , the second parameter is dom node

 

 

2, class declaration

Guess you like

Origin www.cnblogs.com/wskb/p/11021462.html