1.react的安装
- 确保您安装了最新版本的 Node.js 。
npm install -g create-react-app
//全局安装reactcreate-react-app my-app
//创建一个新项目 my-appcd my-app
npm start
//浏览器自动打开 http://localhost:3000
此时入口文件index 和其他组件里可以引用
import React from ‘react’
2.react-dom的安装
npm install react react-dom
安装完成入口文件index 和其他组件里可以引用
import ReactDOM from ‘react-dom’
ReactDom.render( 组件 ,el,()=>{})
3.react router的安装
npm i react-router-dom -S
安装完成入口文件index 和其他组件里可以引用
import { BrowserRouter as Router} from ‘react-router-dom’
import {Route,Link,Redirect,switch,NavLink} from ‘react-router-dom’;
4.redux的安装
npm i redux -D
安装完成入口文件index 和其他组件里可以引用
import { createStore} from “redux”
import {combineReducers} from ‘redux’;//合并reducer
5.redux-thunk的安装
npm install --save redux-thunk
6.react-redux的安装
npm install --save react-redux
安装完成组件里可以引用
import {connect} from ‘react-redux’
import {bindActionCreators} from ‘redux’;
import {Provider} from ‘react-redux’;
以上都安装完成后 项目配置文件package.json下显示如下:
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-redux": "^5.0.7",
"react-scripts": "1.1.4",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"redux": "^4.0.0"
}
}