foxact 0.2.24 → 0.2.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +19 -19
- package/sizes.json +1 -1
- package/use-local-storage/index.cjs +1 -1
- package/use-local-storage/index.d.ts +20 -2
- package/use-local-storage/index.js +1 -1
- package/use-local-storage/index.mjs +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Written in TypeScript. Unlocking strong typing benefits with TypeScript 4.8+.
|
|
|
26
26
|
|
|
27
27
|
#### Super Lightweight
|
|
28
28
|
|
|
29
|
-
The entire **foxact** library has zero dependencies
|
|
29
|
+
The entire **foxact** library has zero dependencies, ensuring a lean and efficient solution. And what's more...
|
|
30
30
|
|
|
31
31
|
#### Fully Tree Shakable
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foxact",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.26",
|
|
4
4
|
"description": "React Hooks/Utils done right. For browser, SSR, and React Server Components.",
|
|
5
5
|
"homepage": "https://foxact.skk.moe",
|
|
6
6
|
"repository": {
|
|
@@ -83,24 +83,6 @@
|
|
|
83
83
|
"require": "./context-state/index.cjs",
|
|
84
84
|
"default": "./context-state/index.js"
|
|
85
85
|
},
|
|
86
|
-
"./create-context-state": {
|
|
87
|
-
"types": "./create-context-state/index.d.ts",
|
|
88
|
-
"import": {
|
|
89
|
-
"types": "./create-context-state/index.d.ts",
|
|
90
|
-
"default": "./create-context-state/index.mjs"
|
|
91
|
-
},
|
|
92
|
-
"require": "./create-context-state/index.cjs",
|
|
93
|
-
"default": "./create-context-state/index.js"
|
|
94
|
-
},
|
|
95
|
-
"./create-fixed-array": {
|
|
96
|
-
"types": "./create-fixed-array/index.d.ts",
|
|
97
|
-
"import": {
|
|
98
|
-
"types": "./create-fixed-array/index.d.ts",
|
|
99
|
-
"default": "./create-fixed-array/index.mjs"
|
|
100
|
-
},
|
|
101
|
-
"require": "./create-fixed-array/index.cjs",
|
|
102
|
-
"default": "./create-fixed-array/index.js"
|
|
103
|
-
},
|
|
104
86
|
"./no-ssr": {
|
|
105
87
|
"types": "./no-ssr/index.d.ts",
|
|
106
88
|
"import": {
|
|
@@ -128,6 +110,24 @@
|
|
|
128
110
|
"require": "./rem/index.cjs",
|
|
129
111
|
"default": "./rem/index.js"
|
|
130
112
|
},
|
|
113
|
+
"./create-context-state": {
|
|
114
|
+
"types": "./create-context-state/index.d.ts",
|
|
115
|
+
"import": {
|
|
116
|
+
"types": "./create-context-state/index.d.ts",
|
|
117
|
+
"default": "./create-context-state/index.mjs"
|
|
118
|
+
},
|
|
119
|
+
"require": "./create-context-state/index.cjs",
|
|
120
|
+
"default": "./create-context-state/index.js"
|
|
121
|
+
},
|
|
122
|
+
"./create-fixed-array": {
|
|
123
|
+
"types": "./create-fixed-array/index.d.ts",
|
|
124
|
+
"import": {
|
|
125
|
+
"types": "./create-fixed-array/index.d.ts",
|
|
126
|
+
"default": "./create-fixed-array/index.mjs"
|
|
127
|
+
},
|
|
128
|
+
"require": "./create-fixed-array/index.cjs",
|
|
129
|
+
"default": "./create-fixed-array/index.js"
|
|
130
|
+
},
|
|
131
131
|
"./request-idle-callback": {
|
|
132
132
|
"types": "./request-idle-callback/index.d.ts",
|
|
133
133
|
"import": {
|
package/sizes.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"total":{"raw":
|
|
1
|
+
{"total":{"raw":13245,"gzip":8332,"br":0},"exports":{"noop":{"raw":34,"gzip":54,"br":38},"compose-context-provider":{"raw":165,"gzip":150,"br":118},"context-state":{"raw":378,"gzip":243,"br":210},"create-context-state":{"raw":146,"gzip":116,"br":102},"no-ssr":{"raw":187,"gzip":172,"br":143},"create-fixed-array":{"raw":101,"gzip":105,"br":89},"rem":{"raw":589,"gzip":331,"br":285},"use":{"raw":277,"gzip":185,"br":155},"request-idle-callback":{"raw":411,"gzip":232,"br":179},"use-array":{"raw":338,"gzip":247,"br":207},"typescript-happy-forward-ref":{"raw":120,"gzip":104,"br":95},"use-composition-input":{"raw":455,"gzip":282,"br":240},"use-debounced-state":{"raw":410,"gzip":291,"br":247},"use-debounced-value":{"raw":471,"gzip":313,"br":254},"use-clipboard":{"raw":1076,"gzip":617,"br":533},"use-error-boundary":{"raw":245,"gzip":197,"br":173},"use-is-client":{"raw":152,"gzip":144,"br":122},"use-isomorphic-layout-effect":{"raw":179,"gzip":145,"br":115},"use-map":{"raw":355,"gzip":249,"br":213},"use-next-pathname":{"raw":322,"gzip":242,"br":202},"use-intersection":{"raw":1239,"gzip":659,"br":605},"use-local-storage":{"raw":1645,"gzip":763,"br":665},"use-retimer":{"raw":201,"gzip":168,"br":127},"use-react-router-is-match":{"raw":569,"gzip":371,"br":313},"use-react-router-enable-concurrent-navigation":{"raw":956,"gzip":455,"br":382},"use-singleton":{"raw":139,"gzip":131,"br":104},"use-set":{"raw":356,"gzip":243,"br":208},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":467,"gzip":326,"br":257},"use-uncontrolled":{"raw":301,"gzip":232,"br":197},"use-url-hash-state":{"raw":961,"gzip":565,"br":487}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react"),n=require("../noop/index.cjs"),o=require("../use-isomorphic-layout-effect/index.cjs"),
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),n=require("../noop/index.cjs"),o=require("../use-isomorphic-layout-effect/index.cjs"),r=require("../no-ssr/index.cjs");const t="foxact-local-storage",i=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(t,{detail:e}))},l=(e,n)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,n)}catch(e){console.error(e)}finally{i(e)}},a=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{i(e)}},s=e=>{if("undefined"==typeof window)return null;try{return window.localStorage.getItem(e)}catch(e){return console.warn(e),null}},u=()=>{throw r.noSSRError("useLocalStorage cannot be used on the server without a serverValue")},c=e=>"function"==typeof e,d=e=>e;exports.useLocalStorage=function(r,i){var w;let f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const y=e.useCallback(e=>{if("undefined"==typeof window)return n.noop;const o=n=>{"key"in n&&n.key!==r||e()},i=n=>{n.detail===r&&e()};return window.addEventListener("storage",o),window.addEventListener(t,i),()=>{window.removeEventListener("storage",o),window.removeEventListener(t,i)}},[r]),v=f.raw?d:f.serializer,p=f.raw?d:f.deserializer,g=void 0!==i?()=>v(i):u,h=e.useSyncExternalStore(y,()=>s(r),g),S=e.useMemo(()=>null===h?null:p(h),[h,p]),m=e.useCallback(e=>{try{const n=c(e)?e(null!=S?S:null):e;null===n?a(r):l(r,v(n))}catch(e){console.warn(e)}},[r,v,S]);return o.useIsomorphicLayoutEffect(()=>{null===s(r)&&void 0!==i&&l(r,v(i))},[p,r,v,i]),[null!==(w=null!=S?S:i)&&void 0!==w?w:null,m]};
|
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
|
|
3
|
+
declare const FOXACT_LOCAL_STORAGE_EVENT_KEY = "foxact-local-storage";
|
|
4
|
+
type CustomStorageEvent = CustomEvent<string>;
|
|
5
|
+
declare global {
|
|
6
|
+
interface WindowEventMap {
|
|
7
|
+
[FOXACT_LOCAL_STORAGE_EVENT_KEY]: CustomStorageEvent;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type Serializer<T> = (value: T) => string;
|
|
11
|
+
type Deserializer<T> = (value: string) => T;
|
|
12
|
+
interface UseLocalStorageRawOption {
|
|
13
|
+
raw: true;
|
|
14
|
+
}
|
|
15
|
+
interface UseLocalStorageParserOption<T> {
|
|
16
|
+
raw?: false;
|
|
17
|
+
serializer: Serializer<T>;
|
|
18
|
+
deserializer: Deserializer<T>;
|
|
19
|
+
}
|
|
20
|
+
type NotUndefined<T> = T extends undefined ? never : T;
|
|
3
21
|
/** @see https://foxact.skk.moe/use-local-storage */
|
|
4
|
-
declare function useLocalStorage<T
|
|
22
|
+
declare function useLocalStorage<T>(key: string, serverValue?: NotUndefined<T> | undefined, options?: UseLocalStorageRawOption | UseLocalStorageParserOption<T>): readonly [NonNullable<T> | null, react.Dispatch<react.SetStateAction<T | null>>];
|
|
5
23
|
|
|
6
|
-
export { useLocalStorage };
|
|
24
|
+
export { type Deserializer, type Serializer, type UseLocalStorageParserOption, type UseLocalStorageRawOption, useLocalStorage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react"),n=require("../noop/index.js"),o=require("../use-isomorphic-layout-effect/index.js"),
|
|
1
|
+
"use strict";require("client-only");var e=require("react"),n=require("../noop/index.js"),o=require("../use-isomorphic-layout-effect/index.js"),r=require("../no-ssr/index.js");const t="foxact-local-storage",i=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(t,{detail:e}))},l=(e,n)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,n)}catch(e){console.error(e)}finally{i(e)}},a=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{i(e)}},s=e=>{if("undefined"==typeof window)return null;try{return window.localStorage.getItem(e)}catch(e){return console.warn(e),null}},u=()=>{throw r.noSSRError("useLocalStorage cannot be used on the server without a serverValue")},d=e=>"function"==typeof e,c=e=>e;exports.useLocalStorage=function(r,i){var w;let f=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const y=e.useCallback(e=>{if("undefined"==typeof window)return n.noop;const o=n=>{"key"in n&&n.key!==r||e()},i=n=>{n.detail===r&&e()};return window.addEventListener("storage",o),window.addEventListener(t,i),()=>{window.removeEventListener("storage",o),window.removeEventListener(t,i)}},[r]),v=f.raw?c:f.serializer,p=f.raw?c:f.deserializer,g=void 0!==i?()=>v(i):u,h=e.useSyncExternalStore(y,()=>s(r),g),S=e.useMemo(()=>null===h?null:p(h),[h,p]),m=e.useCallback(e=>{try{const n=d(e)?e(null!=S?S:null):e;null===n?a(r):l(r,v(n))}catch(e){console.warn(e)}},[r,v,S]);return o.useIsomorphicLayoutEffect(()=>{null===s(r)&&void 0!==i&&l(r,v(i))},[p,r,v,i]),[null!==(w=null!=S?S:i)&&void 0!==w?w:null,m]};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useSyncExternalStore as
|
|
1
|
+
import"client-only";import{useCallback as e,useSyncExternalStore as n,useMemo as o}from"react";import{noop as t}from"../noop/index.mjs";import{useIsomorphicLayoutEffect as r}from"../use-isomorphic-layout-effect/index.mjs";import{noSSRError as i}from"../no-ssr/index.mjs";const l="foxact-local-storage",a=e=>{"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent(l,{detail:e}))},d=(e,n)=>{if("undefined"!=typeof window)try{window.localStorage.setItem(e,n)}catch(e){console.error(e)}finally{a(e)}},s=e=>{if("undefined"!=typeof window)try{window.localStorage.removeItem(e)}catch(e){console.error(e)}finally{a(e)}},w=e=>{if("undefined"==typeof window)return null;try{return window.localStorage.getItem(e)}catch(e){return console.warn(e),null}},u=()=>{throw i("useLocalStorage cannot be used on the server without a serverValue")},c=e=>"function"==typeof e,f=e=>e;function m(i,a){var m;let y=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{serializer:JSON.stringify,deserializer:JSON.parse};const p=e(e=>{if("undefined"==typeof window)return t;const n=n=>{"key"in n&&n.key!==i||e()},o=n=>{n.detail===i&&e()};return window.addEventListener("storage",n),window.addEventListener(l,o),()=>{window.removeEventListener("storage",n),window.removeEventListener(l,o)}},[i]),v=y.raw?f:y.serializer,g=y.raw?f:y.deserializer,h=void 0!==a?()=>v(a):u,S=n(p,()=>w(i),h),E=o(()=>null===S?null:g(S),[S,g]),L=e(e=>{try{const n=c(e)?e(null!=E?E:null):e;null===n?s(i):d(i,v(n))}catch(e){console.warn(e)}},[i,v,E]);return r(()=>{null===w(i)&&void 0!==a&&d(i,v(a))},[g,i,v,a]),[null!==(m=null!=E?E:a)&&void 0!==m?m:null,L]}export{m as useLocalStorage};
|