foxact 0.2.46 → 0.2.48

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.
@@ -1 +1 @@
1
- "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.cjs");exports.createContextState=function(n){const o=t.createContext(n),u=t.createContext(r.noop);return[r=>{let{children:c}=r;const[i,s]=t.useState(n);return e.jsx(o.Provider,{value:i,children:e.jsx(u.Provider,{value:s,children:c})})},()=>t.useContext(o),()=>t.useContext(u),o]};
1
+ "use strict";var e=require("react/jsx-runtime");require("client-only");var t=require("react"),r=require("../noop/index.cjs");exports.createContextState=function(n){const i=t.createContext(n),o=t.createContext(r.noop);return[r=>{let{children:u,initialState:a}=r;const[c,s]=t.useState(null!=a?a:n);return e.jsx(i.Provider,{value:c,children:e.jsx(o.Provider,{value:s,children:u})})},()=>t.useContext(i),()=>t.useContext(o),i]};
@@ -1,5 +1,8 @@
1
1
  import { Foxact } from '../types/index.js';
2
2
 
3
+ interface ProviderProps<T> {
4
+ initialState?: T | (() => T);
5
+ }
3
6
  /** @see https://foxact.skk.moe/context-state */
4
7
  declare function createContextState<T>(initialState: T): [
5
8
  Provider: React.ComponentType<Foxact.PropsWithChildren>,
@@ -7,5 +10,17 @@ declare function createContextState<T>(initialState: T): [
7
10
  useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
8
11
  StateContext: React.Context<T>
9
12
  ];
13
+ declare function createContextState<T>(initialState: T): [
14
+ Provider: React.ComponentType<Foxact.PropsWithChildren<ProviderProps<T>>>,
15
+ useValue: () => T,
16
+ useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
17
+ StateContext: React.Context<T>
18
+ ];
19
+ declare function createContextState<T>(): [
20
+ Provider: React.ComponentType<Foxact.PropsWithChildren<Required<ProviderProps<T>>>>,
21
+ useValue: () => T,
22
+ useSetValue: () => React.Dispatch<React.SetStateAction<T>>,
23
+ StateContext: React.Context<T>
24
+ ];
10
25
 
11
26
  export { createContextState };
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import"client-only";import{useContext as t,createContext as e,useState as o}from"react";import{noop as n}from"../noop/index.mjs";function i(i){const c=e(i),m=e(n);return[t=>{let{children:e}=t;const[n,l]=o(i);return r(c.Provider,{value:n,children:r(m.Provider,{value:l,children:e})})},()=>t(c),()=>t(m),c]}export{i as createContextState};
1
+ import{jsx as t}from"react/jsx-runtime";import"client-only";import{useContext as r,createContext as e,useState as o}from"react";import{noop as n}from"../noop/index.mjs";function i(i){const l=e(i),c=e(n);return[r=>{let{children:e,initialState:n}=r;const[m,a]=o(null!=n?n:i);return t(l.Provider,{value:m,children:t(c.Provider,{value:a,children:e})})},()=>r(l),()=>r(c),l]}export{i as createContextState};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foxact",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
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": {
@@ -47,14 +47,14 @@
47
47
  "exports": {
48
48
  "./package.json": "./package.json",
49
49
  "./sizes.json": "./sizes.json",
50
- "./compose-context-provider": {
51
- "types": "./compose-context-provider/index.d.ts",
50
+ "./context-state": {
51
+ "types": "./context-state/index.d.ts",
52
52
  "import": {
53
- "types": "./compose-context-provider/index.d.ts",
54
- "default": "./compose-context-provider/index.mjs"
53
+ "types": "./context-state/index.d.ts",
54
+ "default": "./context-state/index.mjs"
55
55
  },
56
- "require": "./compose-context-provider/index.cjs",
57
- "default": "./compose-context-provider/index.cjs"
56
+ "require": "./context-state/index.cjs",
57
+ "default": "./context-state/index.cjs"
58
58
  },
59
59
  "./create-context-state": {
60
60
  "types": "./create-context-state/index.d.ts",
@@ -101,14 +101,14 @@
101
101
  "require": "./create-storage-hook/index.cjs",
102
102
  "default": "./create-storage-hook/index.cjs"
103
103
  },
104
- "./context-state": {
105
- "types": "./context-state/index.d.ts",
104
+ "./compose-context-provider": {
105
+ "types": "./compose-context-provider/index.d.ts",
106
106
  "import": {
107
- "types": "./context-state/index.d.ts",
108
- "default": "./context-state/index.mjs"
107
+ "types": "./compose-context-provider/index.d.ts",
108
+ "default": "./compose-context-provider/index.mjs"
109
109
  },
110
- "require": "./context-state/index.cjs",
111
- "default": "./context-state/index.cjs"
110
+ "require": "./compose-context-provider/index.cjs",
111
+ "default": "./compose-context-provider/index.cjs"
112
112
  },
113
113
  "./create-storage-state-factory": {
114
114
  "types": "./create-storage-state-factory/index.d.ts",
@@ -119,15 +119,6 @@
119
119
  "require": "./create-storage-state-factory/index.cjs",
120
120
  "default": "./create-storage-state-factory/index.cjs"
121
121
  },
122
- "./email-protection": {
123
- "types": "./email-protection/index.d.ts",
124
- "import": {
125
- "types": "./email-protection/index.d.ts",
126
- "default": "./email-protection/index.mjs"
127
- },
128
- "require": "./email-protection/index.cjs",
129
- "default": "./email-protection/index.cjs"
130
- },
131
122
  "./current-year": {
132
123
  "types": "./current-year/index.d.ts",
133
124
  "import": {
@@ -137,6 +128,15 @@
137
128
  "require": "./current-year/index.cjs",
138
129
  "default": "./current-year/index.cjs"
139
130
  },
131
+ "./email-protection": {
132
+ "types": "./email-protection/index.d.ts",
133
+ "import": {
134
+ "types": "./email-protection/index.d.ts",
135
+ "default": "./email-protection/index.mjs"
136
+ },
137
+ "require": "./email-protection/index.cjs",
138
+ "default": "./email-protection/index.cjs"
139
+ },
140
140
  "./fetch-jsonp": {
141
141
  "types": "./fetch-jsonp/index.d.ts",
142
142
  "import": {
package/sizes.json CHANGED
@@ -1 +1 @@
1
- {"total":{"raw":23599,"gzip":14509,"br":0},"exports":{"compose-context-provider":{"raw":177,"gzip":155,"br":122},"create-context-state":{"raw":145,"gzip":116,"br":96},"create-fixed-array":{"raw":452,"gzip":282,"br":248},"create-session-storage-state":{"raw":332,"gzip":182,"br":152},"context-state":{"raw":377,"gzip":241,"br":207},"email-protection":{"raw":426,"gzip":321,"br":272},"create-storage-state-factory":{"raw":519,"gzip":309,"br":263},"create-local-storage-state":{"raw":328,"gzip":183,"br":154},"invariant":{"raw":178,"gzip":156,"br":118},"is-safari":{"raw":248,"gzip":164,"br":117},"current-year":{"raw":592,"gzip":400,"br":326},"noop":{"raw":33,"gzip":53,"br":37},"create-storage-hook":{"raw":2073,"gzip":880,"br":764},"nullthrow":{"raw":187,"gzip":163,"br":121},"no-ssr":{"raw":474,"gzip":316,"br":260},"fetch-jsonp":{"raw":875,"gzip":533,"br":418},"types":{"raw":0,"gzip":20,"br":1},"typescript-happy-forward-ref":{"raw":119,"gzip":103,"br":80},"request-idle-callback":{"raw":410,"gzip":229,"br":175},"open-new-tab":{"raw":344,"gzip":260,"br":190},"rem":{"raw":823,"gzip":395,"br":350},"use":{"raw":283,"gzip":185,"br":154},"use-abortable-effect":{"raw":215,"gzip":170,"br":144},"use-array":{"raw":322,"gzip":236,"br":202},"use-component-will-receive-update":{"raw":216,"gzip":188,"br":154},"use-clipboard":{"raw":1177,"gzip":651,"br":552},"use-debounced-value":{"raw":524,"gzip":342,"br":286},"use-error-boundary":{"raw":252,"gzip":195,"br":165},"use-fast-click":{"raw":553,"gzip":364,"br":297},"use-debounced-state":{"raw":401,"gzip":280,"br":242},"use-is-client":{"raw":150,"gzip":145,"br":115},"use-isomorphic-layout-effect":{"raw":178,"gzip":142,"br":112},"use-is-online":{"raw":356,"gzip":212,"br":158},"use-intersection":{"raw":1230,"gzip":649,"br":597},"use-local-storage":{"raw":310,"gzip":184,"br":157},"use-composition-input":{"raw":470,"gzip":286,"br":241},"use-media-query":{"raw":725,"gzip":406,"br":332},"use-map":{"raw":339,"gzip":243,"br":208},"use-next-link":{"raw":1673,"gzip":871,"br":744},"use-page-visibility":{"raw":290,"gzip":206,"br":154},"use-retimer":{"raw":199,"gzip":166,"br":127},"use-react-router-is-match":{"raw":563,"gzip":372,"br":314},"use-session-storage":{"raw":316,"gzip":181,"br":152},"use-next-pathname":{"raw":314,"gzip":235,"br":203},"use-set":{"raw":340,"gzip":238,"br":203},"use-singleton":{"raw":139,"gzip":130,"br":104},"use-typescript-happy-callback":{"raw":107,"gzip":102,"br":77},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":459,"gzip":325,"br":249},"use-react-router-enable-concurrent-navigation":{"raw":966,"gzip":470,"br":397},"use-uncontrolled":{"raw":352,"gzip":258,"br":216},"use-url-hash-state":{"raw":1068,"gzip":616,"br":539}}}
1
+ {"total":{"raw":23624,"gzip":14527,"br":0},"exports":{"create-context-state":{"raw":145,"gzip":116,"br":96},"create-local-storage-state":{"raw":328,"gzip":183,"br":154},"create-fixed-array":{"raw":452,"gzip":282,"br":248},"compose-context-provider":{"raw":177,"gzip":155,"br":122},"context-state":{"raw":402,"gzip":259,"br":221},"create-storage-state-factory":{"raw":519,"gzip":309,"br":263},"create-session-storage-state":{"raw":332,"gzip":182,"br":152},"create-storage-hook":{"raw":2073,"gzip":880,"br":764},"is-safari":{"raw":248,"gzip":164,"br":117},"email-protection":{"raw":426,"gzip":321,"br":272},"noop":{"raw":33,"gzip":53,"br":37},"current-year":{"raw":592,"gzip":400,"br":326},"no-ssr":{"raw":474,"gzip":316,"br":260},"nullthrow":{"raw":187,"gzip":163,"br":121},"open-new-tab":{"raw":344,"gzip":260,"br":190},"fetch-jsonp":{"raw":875,"gzip":533,"br":418},"request-idle-callback":{"raw":410,"gzip":229,"br":175},"rem":{"raw":823,"gzip":395,"br":350},"typescript-happy-forward-ref":{"raw":119,"gzip":103,"br":80},"use-abortable-effect":{"raw":215,"gzip":170,"br":144},"use":{"raw":283,"gzip":185,"br":154},"use-component-will-receive-update":{"raw":216,"gzip":188,"br":154},"types":{"raw":0,"gzip":20,"br":1},"use-array":{"raw":322,"gzip":236,"br":202},"invariant":{"raw":178,"gzip":156,"br":118},"use-composition-input":{"raw":470,"gzip":286,"br":241},"use-debounced-state":{"raw":401,"gzip":280,"br":242},"use-fast-click":{"raw":553,"gzip":364,"br":297},"use-error-boundary":{"raw":252,"gzip":195,"br":165},"use-clipboard":{"raw":1177,"gzip":651,"br":552},"use-intersection":{"raw":1230,"gzip":649,"br":597},"use-isomorphic-layout-effect":{"raw":178,"gzip":142,"br":112},"use-is-online":{"raw":356,"gzip":212,"br":158},"use-local-storage":{"raw":310,"gzip":184,"br":157},"use-is-client":{"raw":150,"gzip":145,"br":115},"use-next-pathname":{"raw":314,"gzip":235,"br":203},"use-page-visibility":{"raw":290,"gzip":206,"br":154},"use-map":{"raw":339,"gzip":243,"br":208},"use-next-link":{"raw":1673,"gzip":871,"br":744},"use-media-query":{"raw":725,"gzip":406,"br":332},"use-retimer":{"raw":199,"gzip":166,"br":127},"use-react-router-is-match":{"raw":563,"gzip":372,"br":314},"use-session-storage":{"raw":316,"gzip":181,"br":152},"use-set":{"raw":340,"gzip":238,"br":203},"use-typescript-happy-callback":{"raw":107,"gzip":102,"br":77},"use-react-router-enable-concurrent-navigation":{"raw":966,"gzip":470,"br":397},"use-singleton":{"raw":139,"gzip":130,"br":104},"use-uncontrolled":{"raw":352,"gzip":258,"br":216},"use-debounced-value":{"raw":524,"gzip":342,"br":286},"use-stable-handler-only-when-you-know-what-you-are-doing-or-you-will-be-fired":{"raw":459,"gzip":325,"br":249},"use-url-hash-state":{"raw":1068,"gzip":616,"br":539}}}