redux进行研究4
react-redux
react-redux为提供了两个api
全局提供store,index.js
import React from 'react'
import ReactDom from 'react-dom'
import App from './App'
import store from './store/ReactReduxStore'
import { Provider } from 'react-redux'
ReactDom.render(
<Provider store={store}>
<App/>
</Provider>,
document.querySelector('#root')
)
获取状态数据,ReduxTest.js
异步
Redux只是个纯粹的状态管理器,默认只⽀持同步,实现异步任务 ⽐如延
迟,⽹络请求,需要中间件的⽀持,⽐如我们试⽤最简单的redux-thunk和
redux-logger
应⽤中间件,store.js
import { createStore, applyMiddleware } from "redux";
import logger from "redux-logger";
import thunk from "redux-thunk";
const store = createStore(fruitReducer,
applyMiddleware(logger, thunk));