Answer the question
In order to leave comments, you need to log in
Why is the state on hooks not updated after dispatch?
This is where I request an array and say redux write it down for me.
useEffect(() => {
axios.get("http://localhost:3000/db.json").then(({ data }) => {
dispatch(pizzasActions.setPizzas(data.pizzas));
});
}, []);
const initialState = {
items: []
};
export const pizzasReducer = (state = initialState, action) => {
switch (action.type) {
case pizzasActionsType.SET_PIZZAS:
return { ...state , items : action.payload};
default:
return state;
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question