summaryrefslogtreecommitdiff
path: root/node_modules/@phntms/use-local-state/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@phntms/use-local-state/lib')
-rw-r--r--node_modules/@phntms/use-local-state/lib/index.d.ts5
-rw-r--r--node_modules/@phntms/use-local-state/lib/index.d.ts.map1
-rw-r--r--node_modules/@phntms/use-local-state/lib/index.js46
-rw-r--r--node_modules/@phntms/use-local-state/lib/index.js.map1
-rw-r--r--node_modules/@phntms/use-local-state/lib/utils.d.ts3
-rw-r--r--node_modules/@phntms/use-local-state/lib/utils.d.ts.map1
-rw-r--r--node_modules/@phntms/use-local-state/lib/utils.js6
-rw-r--r--node_modules/@phntms/use-local-state/lib/utils.js.map1
8 files changed, 64 insertions, 0 deletions
diff --git a/node_modules/@phntms/use-local-state/lib/index.d.ts b/node_modules/@phntms/use-local-state/lib/index.d.ts
new file mode 100644
index 0000000..7c9c492
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/index.d.ts
@@ -0,0 +1,5 @@
+declare type Dispatch<A> = (value: A) => void;
+declare type SetStateAction<S> = S | ((prevState: S) => S);
+declare const useLocalState: <S>(key: string, defaultValue: S | (() => S)) => [S, Dispatch<SetStateAction<S>>, () => void];
+export default useLocalState;
+//# sourceMappingURL=index.d.ts.map \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/index.d.ts.map b/node_modules/@phntms/use-local-state/lib/index.d.ts.map
new file mode 100644
index 0000000..b9df483
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AACtC,aAAK,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAEnD,QAAA,MAAM,aAAa,WACZ,MAAM,yEAE6B,IAAI,CAuC7C,CAAC;AAEF,eAAe,aAAa,CAAC"} \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/index.js b/node_modules/@phntms/use-local-state/lib/index.js
new file mode 100644
index 0000000..12a0de2
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/index.js
@@ -0,0 +1,46 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var react_1 = require("react");
+var utils_1 = require("./utils");
+var useLocalState = function (key, defaultValue) {
+ var _a = (0, react_1.useState)(function () {
+ var isCallable = function (value) {
+ return typeof value === "function";
+ };
+ var toStore = isCallable(defaultValue) ? defaultValue() : defaultValue;
+ if (!utils_1.SUPPORTED)
+ return toStore;
+ var item = window.localStorage.getItem(key);
+ try {
+ return item ? JSON.parse(item) : toStore;
+ }
+ catch (error) {
+ return toStore;
+ }
+ }), value = _a[0], setValue = _a[1];
+ var lastValue = (0, react_1.useRef)(value);
+ lastValue.current = value;
+ var setLocalStateValue = (0, react_1.useCallback)(function (newValue) {
+ var isCallable = function (value) {
+ return typeof value === "function";
+ };
+ var toStore = isCallable(newValue)
+ ? newValue(lastValue.current)
+ : newValue;
+ if (utils_1.SUPPORTED)
+ window.localStorage.setItem(key, JSON.stringify(toStore));
+ setValue(toStore);
+ }, [key]);
+ var reset = (0, react_1.useCallback)(function () {
+ var isCallable = function (value) {
+ return typeof value === "function";
+ };
+ var toStore = isCallable(defaultValue) ? defaultValue() : defaultValue;
+ setValue(toStore);
+ if (utils_1.SUPPORTED)
+ window.localStorage.removeItem(key);
+ }, [defaultValue, key]);
+ return [value, setLocalStateValue, reset];
+};
+exports.default = useLocalState;
+//# sourceMappingURL=index.js.map \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/index.js.map b/node_modules/@phntms/use-local-state/lib/index.js.map
new file mode 100644
index 0000000..1750353
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/index.js.map
@@ -0,0 +1 @@
+{"version":3,"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CAAC,CAAC,CAAC;QACzE,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC,EACD,CAAC,GAAG,CAAC,CACN,CAAC;IAEF,IAAM,KAAK,GAAG,IAAA,mBAAW,EAAC;QACxB,IAAM,UAAU,GAAG,UAAC,KAAc;YAChC,OAAA,OAAO,KAAK,KAAK,UAAU;QAA3B,CAA2B,CAAC;QAC9B,IAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;QACzE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClB,IAAI,iBAAS;YAAE,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACrD,CAAC,EAAE,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,KAAK,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"} \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/utils.d.ts b/node_modules/@phntms/use-local-state/lib/utils.d.ts
new file mode 100644
index 0000000..74f40d9
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/utils.d.ts
@@ -0,0 +1,3 @@
+export declare const IS_BROWSER: boolean;
+export declare const SUPPORTED: false | Storage;
+//# sourceMappingURL=utils.d.ts.map \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/utils.d.ts.map b/node_modules/@phntms/use-local-state/lib/utils.d.ts.map
new file mode 100644
index 0000000..d9f31f3
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/utils.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,SAAgC,CAAC;AAExD,eAAO,MAAM,SAAS,iBAAoC,CAAC"} \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/utils.js b/node_modules/@phntms/use-local-state/lib/utils.js
new file mode 100644
index 0000000..c1c445c
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/utils.js
@@ -0,0 +1,6 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.SUPPORTED = exports.IS_BROWSER = void 0;
+exports.IS_BROWSER = typeof window !== "undefined";
+exports.SUPPORTED = exports.IS_BROWSER && window.localStorage;
+//# sourceMappingURL=utils.js.map \ No newline at end of file
diff --git a/node_modules/@phntms/use-local-state/lib/utils.js.map b/node_modules/@phntms/use-local-state/lib/utils.js.map
new file mode 100644
index 0000000..9213404
--- /dev/null
+++ b/node_modules/@phntms/use-local-state/lib/utils.js.map
@@ -0,0 +1 @@
+{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAE3C,QAAA,SAAS,GAAG,kBAAU,IAAI,MAAM,CAAC,YAAY,CAAC"} \ No newline at end of file