Build Forms with React to Edit mobx-state-tree Models

Share this video with your friends

Send Tweet

We will expand our UI, and give the user the possibility to edit his wishlist. We will use the earlier defined actions. We also will use model clones only to modify data temporarily, and after approving the changes, apply them back to the original model.

In this lesson you will learn:

  • How to call model actions from a component
  • Using clone to create a full, deep clone of any model instance
  • Using applySnapshot to update the state of a model instance given a snapshot.
Gar Liu
~ 7 years ago

const Model = types.model({ name: types.string });

const model = Model.create({ name: 'Gar' });

const cloned = clone(model);

console.log((cloned === model)); //why is this false?????

Thank you :)

Michel Weststrateinstructor
~ 7 years ago

Clones are per definition not the same instance as the original. If it was, it wouldn't be a clone :) So if you clone "Gar", then there are two different "Gar"s with the same properties, but you could start updating them individually.

Op di 20 mrt. 2018 om 16:37 schreef Gar notifications@egghead.io:

Gar Liu
~ 7 years ago

yes indeed. Thanks!!