当前位置: 首页 > 文档资料 > Redux 中文文档 >

API 文档

优质
小牛编辑
121浏览
2023-12-01

Redux 的 API 非常少。Redux 定义了一系列的约定(contract)来让你来实现(例如 reducers),同时提供少量辅助函数来把这些约定整合到一起。

这一章会介绍所有的 Redux API。记住,Redux 只关心如何管理 state。在实际的项目中,你还需要使用 UI 绑定库如 react-redux。

顶级暴露的方法

  • createStore(reducer, [preloadedState], [enhancer])
  • combineReducers(reducers)
  • applyMiddleware(...middlewares)
  • bindActionCreators(actionCreators, dispatch)
  • compose(...functions)

Store API

  • Store
    • getState()
    • dispatch(action)
    • subscribe(listener)
    • getReducer()
    • replaceReducer(nextReducer)

引入

上面介绍的所有函数都是顶级暴露的方法。都可以这样引入:

ES6

import { createStore } from 'redux'

ES5 (CommonJS)

var createStore = require('redux').createStore

ES5 (UMD build)

var createStore = Redux.createStore