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