Вот Редуктор:
function accountReducer(state: StateT = initialState, action: ActionI): StateT {
let newState: StateT = JSON.parse(JSON.stringify(state));
switch (action.type) {
case ADD_CATEGORY:
addCategory(state, action.category);
break;
case UPD_CATEGORY_FIELD_TITLE:
newState = {...state};
newState.category_value = action.title;
console.log(newState.category_value);
console.log(state.category_value);
console.log(newState === state);
break;
case ADD_PRODUCT:
addProduct(state, action.product);
break;
case UPD_PRODUCT_FIELD_TITLE:
updProductFormTitle(state, action.title, action.index);
break;
case UPD_NUM_OF_TEXT_FIELDS:
updNumOfTextFields(state, action.index);
break;
case UPD_PERSONAL_DATA_FORM_TITLE:
updPersonalDataFormTitle(state, action.title, action.index);
break;
default:
return state;
}
console.log(newState === state);
return newState;
}
Получаю
state
, копирую его в
newState
и в зависимости от типа action изменяю в нем что-то. Но ничего не перерисовывается
Вот connect:
function mapStateToProps(
state: CombinedState<{
accountPage: StateT;
catalogPage: StateT;
}>
) {
return {
CategoryForm: state.accountPage
};
}
function mapDispatchToProps(dispatch: (action: ActionI) => void) {
return {
addCategory: (newCategory: string) => {
dispatch(addCategoryActionCreator(newCategory));
},
updCategoryTitle: (newCategory: string) => {
dispatch(updCategoryFormTitleActionCreator(newCategory))
},
};
}
const CategoryFormContainer = connect(
mapStateToProps,
mapDispatchToProps
)(CategoryForm);