@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.
- package/dist/components/layout/_.d.ts +1 -1
- package/dist/components/layout/_.js +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/state/_.d.ts +1 -0
- package/dist/hooks/state/_.js +1 -0
- package/dist/hooks/state/array.d.ts +9 -0
- package/dist/hooks/state/array.js +19 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as RnD } from "./rnd";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as
|
|
1
|
+
export { default as RnD } from "./rnd";
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./array";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./array";
|
|
@@ -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
|
+
}
|