react-webstorage 直接使用 W3C WebStorage API 的任何实现,作为 React/Flux 风格的存储。首先,导入 WebStorage:


var WebStorage = require('react-webstorage');

var dispatcher = require('./path/to/app-dispatcher');

var webStorage = new WebStorage(window.localStorage || window.sessionStorage /* 或 poly-fill */);

接下来,注册 dispatcher:


dispatcher.register(function (payload) {

    switch (payload.actionType) {

        case 'A':

            webStorage.set(...);

            break;

        // 其他 case

    }

});