我是React + Redux的新手。我很困惑为什么redux状态对象不直接暴露给存储,而是通过store.userReducer。
这是我的连接装饰
@connect((store) => {
return {
users: store.userReducer.users
//users: store.users
}
})
这是combineReducers
import {combineReducers} from "redux";
import userReducer from "./usersReducer";
export default combineReducers({
userReducer
})
这是userReducer的相关部分
export default function reducer(state={
users:[],
fetching: false,
fetched: false,
error: null
}, action){
switch (action.type) {
case "FETCH_USERS":{
return {...state, fetching: true}
}
这是商店的一部分
const middleware = applyMiddleware(promise(),thunk);
export default createStore(reducers,middleware);