UNPKG

@magicbell/react-headless

Version:
27 lines 878 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const zustand_1 = require("zustand"); const ConfigRepository_js_1 = tslib_1.__importDefault(require("./ConfigRepository.js")); /** * Remote configuration store. It contains all settings stored in MagicBell * servers for this user. * * @example * const { fetch } = useConfig(); * useEffect(() => fetch(), []); */ const useConfig = (0, zustand_1.create)((set, get) => ({ channels: undefined, inbox: undefined, ws: undefined, lastFetchedAt: undefined, _repository: new ConfigRepository_js_1.default(), fetch: async () => { const { _repository } = get(); const json = await _repository.get(); set({ ...json, lastFetchedAt: Date.now() }); }, })); exports.default = useConfig; //# sourceMappingURL=useConfig.js.map