@bouko/react 3.1.4 → 3.1.6

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.
@@ -17,9 +17,17 @@ export declare function useRequestGate(): {
17
17
  };
18
18
  type Props<T> = {
19
19
  fetcher: () => Promise<T>;
20
- updater: (x?: T) => Promise<void>;
20
+ updater: (x?: T) => Promise<T | null>;
21
21
  };
22
22
  export declare function useValue<T>({ fetcher, updater }: Props<T>): {
23
23
  value: T | null;
24
24
  update: (x?: T) => Promise<void>;
25
25
  };
26
+ type ConfigProps<T> = {
27
+ fetcher: () => Promise<Record<string, T> | null>;
28
+ updater: (x: string, value: T) => Promise<T>;
29
+ };
30
+ export declare function useConfig<T>({ fetcher, updater }: ConfigProps<T>): {
31
+ config: Record<string, T>;
32
+ update: (id: string, x: T) => Promise<void>;
33
+ };
@@ -37,8 +37,20 @@ export function useValue({ fetcher, updater }) {
37
37
  .then(setValue);
38
38
  }, []);
39
39
  const update = async (x) => {
40
- await updater(x);
41
- setValue(x || null);
40
+ const res = await updater(x);
41
+ setValue(res || null);
42
42
  };
43
43
  return { value, update };
44
44
  }
45
+ export function useConfig({ fetcher, updater }) {
46
+ const [config, setConfig] = useState({});
47
+ useEffect(() => {
48
+ fetcher()
49
+ .then(x => setConfig(x || {}));
50
+ }, []);
51
+ const update = async (id, x) => {
52
+ const res = await updater(id, x);
53
+ setConfig(prev => ({ ...prev, [id]: res }));
54
+ };
55
+ return { config, update };
56
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "3.1.4",
4
+ "version": "3.1.6",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",