UNPKG

@channel-state/react

Version:

React hooks for channel-state, providing seamless integration with React applications for cross-context state management.

66 lines (60 loc) 2.34 kB
var ChannelState = (function (exports) { 'use strict'; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. __defProp(target, "default", { value: mod, enumerable: true }) , mod )); // globals:react var require_react = __commonJS({ "globals:react"(exports, module) { module.exports = React; } }); // src/index.ts var import_react = __toESM(require_react()); function useChannelState(store) { const value = (0, import_react.useSyncExternalStore)( (onStoreChange) => store.subscribe(onStoreChange), () => store.get(), () => store.get() ); const set = (newValue) => { store.set(newValue); }; return [value, set]; } function useChannelStatus(store) { const status = (0, import_react.useSyncExternalStore)( (onStoreStatusChange) => store.subscribeStatus(onStoreStatusChange), () => store.status, () => store.status ); return status; } exports.useChannelState = useChannelState; exports.useChannelStatus = useChannelStatus; return exports; })({}); //# sourceMappingURL=index.global.js.map //# sourceMappingURL=index.global.js.map