Answer the question
In order to leave comments, you need to log in
Is it possible to somehow get the first initialState of redux in react?
Is it possible to somehow get the first initialState of redux in react?
for example, I have a car filter and one property depends on another,
i.e. when i change type_transport_id i need to reset brand_id, automodel_id, year, and body_id to initial state, but when i change brand_id i need to reset automodel_id, year, and body_id etc.
brand_model : {
type_transport_id: null,
brand_id: null,
automodel_id: null,
year: null,
body_id: null,
}
Answer the question
In order to leave comments, you need to log in
const initialState = {
type_transport_id: null,
brand_id: null,
automodel_id: null,
year: null,
body_id: null,
};
export default function model(state = initialState, action) {
const { type, payload } = action;
switch(type) {
case SET_TYPE:
return {
...initialState,
type_transport_id: payload,
};
case SET_BRAND:
return {
...state,
brand_id: payload,
automodel_id: null,
year: null,
body_id: null,
};
default:
return state;
}
}
case SET_BRAND:
return {
...initialState,
type_transport_id: state.type_transport_id,
brand_id: payload,
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question