Tôi có bộ giảm tốc và để tính toán trạng thái mới, tôi cần dữ liệu từ hành động và dữ liệu từ một phần của trạng thái không được trình giảm tốc này quản lý. Cụ thể, trong trình giảm tốc tôi sẽ hiển thị bên dưới, tôi cần quyền truy cập vào trường accountDetails.stateOfResidenceId
.Làm cách nào để truy cập trạng thái bên trong bộ giảm tốc Redux?
initialState.js:
export default {
accountDetails: {
stateOfResidenceId: '',
accountType: '',
accountNumber: '',
product: ''
},
forms: {
blueprints: [
]
}
};
formsReducer.js:
import * as types from '../constants/actionTypes';
import objectAssign from 'object-assign';
import initialState from './initialState';
import formsHelper from '../utils/FormsHelper';
export default function formsReducer(state = initialState.forms, action) {
switch (action.type) {
case types.UPDATE_PRODUCT: {
//I NEED accountDetails.stateOfResidenceId HERE
console.log(state);
const formBlueprints = formsHelper.getFormsByProductId(action.product.id);
return objectAssign({}, state, {blueprints: formBlueprints});
}
default:
return state;
}
}
index.js (root giảm):
import { combineReducers } from 'redux';
import accountDetails from './accountDetailsReducer';
import forms from './formsReducer';
const rootReducer = combineReducers({
accountDetails,
forms
});
export default rootReducer;
Tôi làm cách nào để truy cập trường này?
[Cập nhật trạng thái dựa trên trạng thái của ứng dụng là một chất chống -pattern] (https://stackoverflow.com/questions/35851837/redux-and-within-a-reducer-accessing-a-different-reducer-how) – Igorsvee
Tuyên bố đó không có ý nghĩa gì cả. Toàn bộ điểm của một hàm giảm tốc là bạn đưa ra quyết định dựa trên * trạng thái hiện tại * và hành động. – markerikson