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

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.

主站蜘蛛池模板: 重庆市| 武陟县| 恭城| 桐庐县| 迁安市| 揭阳市| SHOW| 平江县| 明水县| 图片| 保靖县| 军事| 柳州市| 临湘市| 怀柔区| 洛隆县| 博客| 马龙县| 浮山县| 海丰县| 盐边县| 本溪| 平度市| 靖远县| 会理县| 张家口市| 聂荣县| 涡阳县| 和政县| 宁国市| 永靖县| 静海县| 嘉黎县| 宜丰县| 台中县| 株洲县| 淮北市| 德兴市| 顺平县| 青河县| 仁怀市|