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

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.

主站蜘蛛池模板: 嘉禾县| 油尖旺区| 深泽县| 吉林市| 蒲城县| 齐河县| 太白县| 阜新市| 四会市| 新竹县| 延吉市| 临城县| 松滋市| 始兴县| 横山县| 秦皇岛市| 万荣县| 凤台县| 即墨市| 德阳市| 蒙阴县| 贵溪市| 南昌县| 衡南县| 桦甸市| 梓潼县| 江都市| 正镶白旗| 泰州市| 罗甸县| 崇左市| 兴和县| 普安县| 宝山区| 乌兰县| 慈利县| 瓦房店市| 金沙县| 丰台区| 九龙坡区| 长子县|