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

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.

主站蜘蛛池模板: 锡林郭勒盟| 昭苏县| 项城市| 凌云县| 宁安市| 盐边县| 栾城县| 寻乌县| 青海省| 闵行区| 南岸区| 共和县| 金山区| 闽清县| 信阳市| 绥阳县| 泗阳县| 滁州市| 武城县| 五华县| 来宾市| 招远市| 龙南县| 绥芬河市| 扬州市| 太谷县| 会宁县| 紫阳县| 南部县| 加查县| 宿松县| 宁陕县| 民县| 清水河县| 襄垣县| 海晏县| 锦州市| 高尔夫| 鹿邑县| 裕民县| 南昌市|