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.0 KB
|
Line | |
---|
1 | import { __assign, __rest } from "tslib";
|
---|
2 | import { useCallback, useMemo, useState } from 'react';
|
---|
3 | var useMap = function (initialMap) {
|
---|
4 | if (initialMap === void 0) { initialMap = {}; }
|
---|
5 | var _a = useState(initialMap), map = _a[0], set = _a[1];
|
---|
6 | var stableActions = useMemo(function () { return ({
|
---|
7 | set: function (key, entry) {
|
---|
8 | set(function (prevMap) {
|
---|
9 | var _a;
|
---|
10 | return (__assign(__assign({}, prevMap), (_a = {}, _a[key] = entry, _a)));
|
---|
11 | });
|
---|
12 | },
|
---|
13 | setAll: function (newMap) {
|
---|
14 | set(newMap);
|
---|
15 | },
|
---|
16 | remove: function (key) {
|
---|
17 | set(function (prevMap) {
|
---|
18 | var _a = prevMap, _b = key, omit = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
---|
19 | return rest;
|
---|
20 | });
|
---|
21 | },
|
---|
22 | reset: function () { return set(initialMap); },
|
---|
23 | }); }, [set]);
|
---|
24 | var utils = __assign({ get: useCallback(function (key) { return map[key]; }, [map]) }, stableActions);
|
---|
25 | return [map, utils];
|
---|
26 | };
|
---|
27 | export default useMap;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.