source: imaps-frontend/node_modules/react-use/esm/useSet.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import { __assign, __spreadArrays } from "tslib";
2import { useCallback, useMemo, useState } from 'react';
3var useSet = function (initialSet) {
4 if (initialSet === void 0) { initialSet = new Set(); }
5 var _a = useState(initialSet), set = _a[0], setSet = _a[1];
6 var stableActions = useMemo(function () {
7 var add = function (item) { return setSet(function (prevSet) { return new Set(__spreadArrays(Array.from(prevSet), [item])); }); };
8 var remove = function (item) {
9 return setSet(function (prevSet) { return new Set(Array.from(prevSet).filter(function (i) { return i !== item; })); });
10 };
11 var toggle = function (item) {
12 return setSet(function (prevSet) {
13 return prevSet.has(item)
14 ? new Set(Array.from(prevSet).filter(function (i) { return i !== item; }))
15 : new Set(__spreadArrays(Array.from(prevSet), [item]));
16 });
17 };
18 return { add: add, remove: remove, toggle: toggle, reset: function () { return setSet(initialSet); }, clear: function () { return setSet(new Set()); } };
19 }, [setSet]);
20 var utils = __assign({ has: useCallback(function (item) { return set.has(item); }, [set]) }, stableActions);
21 return [set, utils];
22};
23export default useSet;
Note: See TracBrowser for help on using the repository browser.