Skip to content

How to add multiple items? #1708

Answered by EmilTholin
thanksyouall asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @thanksyouall!

You can use the merge method:

const MyModel = types
  .model({
    members: types.map(Member)
  })
  .actions((self) => ({
    someAction(members: any) {
      self.members.merge(members);
    }
  }));

const myModel = MyModel.create({
  members: {
    "1": {
      id: "1",
      name: "foo"
    },
    "2": {
      id: "2",
      name: "bar"
    }
  }
});

myModel.someAction({
  "3": { id: "3", name: "baz" },
  "4": { id: "4", name: "quz" }
});

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@thanksyouall
Comment options

Answer selected by thanksyouall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants