官术网_书友最值得收藏!

An observable state

The state is at the epicenter of all things happening in the UI. MobX provides a core building block, called the observable, that represents the reactive state of your application. Any JavaScript object can be used to create an observable. We can use the aptly named observable() API as follows:

import {observable} from 'mobx';

let cart = observable({
itemCount: 0,
modified: new Date()
});

In the preceding example, we have created a simple cart object that is also an observable. The observable() API comes from the mobx NPM package. With this simple declaration of an observable, we now have a reactive cart that keeps track of changes happening on any of its properties: itemCount and modified.

主站蜘蛛池模板: 遂昌县| 宁都县| 汝阳县| 临湘市| 南安市| 舟山市| 刚察县| 宝清县| 都昌县| 五河县| 东莞市| 芮城县| 阜南县| 葫芦岛市| 泰来县| 新源县| 苍梧县| 昌邑市| 雷州市| 仁化县| 合肥市| 新宁县| 乌拉特中旗| 开平市| 高尔夫| 龙胜| 平湖市| 囊谦县| 澄迈县| 萝北县| 视频| 南陵县| 镇巴县| 年辖:市辖区| 新乡县| 城步| 攀枝花市| 策勒县| 定陶县| 巴林右旗| 丽水市|