Easy-peasy: Interacting between models

Created on 10 Oct 2020  路  2Comments  路  Source: ctrlplusb/easy-peasy

easy-peasy
How can I update different module?

Most helpful comment

@1alexvash you can update nested state within the action.

Actions receive the state local to them, which includes the state below them too.

We can complete your code like so:

const store = createStore({
  products: {
    fruits: ["馃崗", "馃崐", "馃崒"],
  },
  addFruit: action((state, payload) => {
    state.products.fruit.push(payload);
  }),
});

store.getActions().addFruit("馃崏");

馃槉

All 2 comments

@1alexvash

Can you elaborate more in detail what exactly you are trying to accomplish? Are you trying to add a new fruit?

@1alexvash you can update nested state within the action.

Actions receive the state local to them, which includes the state below them too.

We can complete your code like so:

const store = createStore({
  products: {
    fruits: ["馃崗", "馃崐", "馃崒"],
  },
  addFruit: action((state, payload) => {
    state.products.fruit.push(payload);
  }),
});

store.getActions().addFruit("馃崏");

馃槉

Was this page helpful?
0 / 5 - 0 ratings