react-state-bucket
Version:
A lightweight and powerful package designed to manage states globally in React applications. It provides CRUD operations for your state data with ease, enabling developers to handle complex state management scenarios without the need for heavy libraries.
17 lines (16 loc) • 722 B
JavaScript
;Object.defineProperty(exports,'__esModule',{value:true});var react=require('react'),xanv=require('xanv'),Bucket=require('./Bucket.js');const createBucket = (initial, option) => {
const bucket = new Bucket.default(initial, option);
const useBucket = () => {
const id = "rsb_" + react.useId();
const [, setState] = react.useState(0);
react.useEffect(() => {
bucket.subscribe(id, () => setState(Math.random()));
return () => {
bucket.unsubscribe(id);
};
}, [id]);
return bucket;
};
return useBucket;
};
const xv = xanv.xv;exports.createBucket=createBucket;exports.xv=xv;//# sourceMappingURL=index.js.map