1.安裝構建工具react
npm install -g create-react-app
webpack
2.構建項目web
create-react-app ProjectName
npm
3.安裝reduxjson
npm install redux --save npm run eject 彈出配置文件 可自定義配置webpack
4.安裝異步處理 redux-thunknpm install redux-thunk --save
使用applyMiddleware開啓 thunk中間件redux
5.安裝鏈接 react-redux npm install react-redux --save
React-redux 提供 Provider和connect 兩個接口來鏈接
Provider組件在應用最外層,傳入store便可,只用一次
Connect負責從外部獲取組件所需的參數babel
6.安裝裝飾器 npm install babel-plugin-transform-decorators-legacy --save-dev
package.json 的 babel 中加入react-router
"plugins": [ "transform-decorators-legacy" ]
connect的使用變得簡潔app
@connect( (state) => {{num: state}}, // 屬性 { addGun, removeGun, addGunAsync } // 方法 )
7.React-Router 4npm install react-router-dom --save
dom