const INITIAL_STATE = { values: {} }; const reducerUpdate = (state = INITIAL_STATE, action) => { switch (action.type) { case types.FORM_UPDATE_VALUE: return Object.assign({}, state, { values: Object.assign({}, state.values, { [action.name]: action.value, }) }); case types.FORM_RESET: return INITIAL_STATE; // here I need isLoading value from reducerRegister.js } return state; }; export default reducerUpdate;
reducerCombined.js
import { combineReducers } from 'redux'; import reducerRegister from './reducerRegister'; import reducerLogin from './reducerLogin'; import reducerForm from './reducerForm';
Many users later want to try to share data between two reducers, but find that combineReducers does not allow them to do so. There are several approaches that can be used:
If a reducer needs to know data from another slice of state, the state tree shape may need to be reorganized so that a single reducer is handling more of the data.
You may need to write some custom functions for handling some of these actions. This may require replacing combineReducers with your own top-level reducer function. You can also use a utility such as reduce-reducers to run combineReducers to handle most actions, but also run a more specialized reducer for specific actions that cross state slices.
Async action creators such as redux-thunk have access to the entire state through getState(). An action creator can retrieve additional data from the state and put it in an action, so that each reducer has enough information to update its own state slice.
Tôi là một lập trình viên xuất sắc, rất giỏi!