@bouko/react 3.2.2 → 3.2.3

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
- export { default as Rnd } from "./rnd";
1
+ export { default as RnD } from "./rnd";
@@ -1 +1 @@
1
- export { default as Rnd } from "./rnd";
1
+ export { default as RnD } from "./rnd";
@@ -31,3 +31,4 @@ export declare function useConfig<T>({ fetcher, updater }: ConfigProps<T>): {
31
31
  };
32
32
  export * from "./auth";
33
33
  export * from "./audio/_";
34
+ export * from "./state/_";
@@ -54,3 +54,4 @@ export function useConfig({ fetcher, updater }) {
54
54
  }
55
55
  export * from "./auth";
56
56
  export * from "./audio/_";
57
+ export * from "./state/_";
@@ -0,0 +1 @@
1
+ export * from "./array";
@@ -0,0 +1 @@
1
+ export * from "./array";
@@ -0,0 +1,9 @@
1
+ export declare function useArrayState<T extends {
2
+ id?: string;
3
+ }>(initial?: T[]): {
4
+ items: T[];
5
+ add: (entry: T) => void;
6
+ updateOne: (id: string, entry: Partial<T>) => void;
7
+ remove: (id: string) => void;
8
+ clear: () => void;
9
+ };
@@ -0,0 +1,19 @@
1
+ import { useState } from "react";
2
+ export function useArrayState(initial = []) {
3
+ const [items, setItems] = useState(initial);
4
+ const add = (entry) => setItems(prev => [...prev, entry]);
5
+ const remove = (id) => setItems(prev => prev.filter(x => x.id !== id));
6
+ const updateOne = (id, entry) => {
7
+ setItems(prev => prev.map((x, i) => x.id === id ? { ...x, ...entry } : x));
8
+ };
9
+ const clear = () => {
10
+ setItems([]);
11
+ };
12
+ return {
13
+ items,
14
+ add,
15
+ updateOne,
16
+ remove,
17
+ clear
18
+ };
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/react",
4
- "version": "3.2.2",
4
+ "version": "3.2.3",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",