在动作创建者中访问Redux状态?
说我有以下内容:
export const SOME_ACTION = 'SOME_ACTION';export function someAction() { return { type: SOME_ACTION, }}
在该动作创建者中,我想访问全局存储状态(所有reducers)。这样做更好:
import store from '../store';export const SOME_ACTION = 'SOME_ACTION';export function someAction() { return { type: SOME_ACTION, items: store.getState().otherReducer.items, }}
或这个:
export const SOME_ACTION = 'SOME_ACTION';export function someAction() { return (dispatch, getState) => { const {items} = getState().otherReducer; dispatch(anotherAction(items)); }}
慕村9548890
潇潇雨雨
当年话下
相关分类