P
P
Popachka2022-04-08 23:18:53
React
Popachka, 2022-04-08 23:18:53

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));
    });
  }, []);

Then it arrives well, action is fine. And it seems like it should overwrite everything in the state, but this does not happen. state.items = undefined
const initialState = {
  items: []
};

export const pizzasReducer = (state = initialState, action) => {
  switch (action.type) {
    case pizzasActionsType.SET_PIZZAS:
      return { ...state , items : action.payload};
    default:
      return state;
  }
};

6250a21b1a094779790487.jpeg6250a222d614d820867123.jpeg
What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2022-04-08
@Popachka

A typo - you are passing payOlad , and the data in the reducer is taken from action.payload . I recommend installing plugins, such as code spell checker, it helps a lot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question