The Store Model
Introduction to the store model of MobX State Tree
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Building a React App with MobX State Tree course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Building a React App with MobX State Tree, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
[00:00 - 00:09] Hello everyone, welcome to this video. In this video, we're going to set up MobX Day 3 and MobX because it's a dependency of MobX Day 3 because it's built on top of it.
[00:10 - 00:22] First, we're going to use Yarn to install our dependencies. Dependencies install, now we see that we have MobX Day 3 5.1.6 and MobX 6.6.1, which both of them are the latest.
[00:23 - 00:30] We are importing types from the MobX Day 3 package. After it, we are going to define our modal shape.
[00:31 - 00:36] The modal function takes two arguments. The first one being the debugging name of the store.
[00:37 - 00:44] And the second one is going to be an object which defines the shape of the store. We have name, which is a type string.
[00:45 - 00:50] We have last name, which is also a type string. And we have H, which is a type number.
[00:51 - 00:58] Now we need to instantiate this store. We use the .create method from the model that we have just created.
[00:59 - 01:09] We need to pass an object with the default values that this instance is going to take at initialization time. Now we're going to take a look at how this instance looks.
[01:10 - 01:26] We have an object with various properties which are get us on setters because MobX Day 3 uses proxies to prevent you from manipulating the state directly. We also have a name, a last name, and an H.
[01:27 - 01:41] We can see that we can retrieve values easily just by accessing it as it was a plain object. So as you can see, quite simple and straightforward little boilerplate and ready for the next lesson.
[01:42 - 01:43] See you in the next video.