动作触发但存储未更新,当动作在单个对象中时动作不起作用,带有返回方法的单独动作起作用
动作.js
export const actions = {
GET_ORDERS_COUNT:'GET_ORDERS_COUNT'
};
order.js
class OrderDashboard extends React.Component {
constructor(props) {
super(props);
this.state = {}
}
componentDidMount() {
store.dispatch({
type: actions.GET_ORDERS_COUNT
});
}
}
export default connect(mapStateToProps, {actions})(OrderDashboard);
减速器.js
const initState = {
dashboardData:0
};
export default function (state = initState, action) {
switch (action.type) {
case actions.GET_ORDERS_COUNT: {
return {
...state,
dashboardData: 5,
}
}
}