You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2、createStore
创建一个 Redux store 来以存放应用中所有的 state,应用中应有且仅有一个 store
实例1:
import { createStore } from 'redux'
function todos(state = [], action) {
switch (action.type) {
case 'ADD_TODO':
return state.concat([action.text])
default:
return state
}
}
let store = createStore(todos, ['Use Redux'])
redux(中文官网)
redux 简单来说就是起到状态管理的功能
优点
数据单向流
API
1、简单的例子如下:
2、createStore
创建一个 Redux store 来以存放应用中所有的 state,应用中应有且仅有一个 store
实例1:
接入React
注意Provider 是react-redux的API
3、combineReducers
作用是把多个reducers合成一个reducer
实例:
4、applyMiddleware(源码很精练,大家可以研究一下)
扩展中间件
实例:
5、bindActionCreators(actionCreators, dispatch)
包装action,作用可以包装action解除耦合
6、compose
函数的柯里化,具体不在介绍
react-redux
2个api
1、Provider
createStore的api已经介绍过实例
2、connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
The text was updated successfully, but these errors were encountered: