react-state-monad 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
package/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./src/hooks/useFieldState";
2
+ export * from "./src/hooks/useElementState";
3
+ export * from "./src/hooks/useEmptyState";
4
+ export * from "./src/hooks/useFieldState";
5
+ export * from "./src/hooks/useRemapArray";
6
+ export * from "./src/hooks/useStateObject";
7
+ export * from "./src/stateObject";
8
+
9
+ export default this;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-state-monad",
3
3
  "type": "module",
4
- "version": "1.0.7",
4
+ "version": "1.0.8",
5
5
  "description": "A set of hooks to manage/transform/filter states with monads in React",
6
6
  "keywords": [
7
7
  "maybe",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "validateTypes": "tsc --noEmit",
17
- "build": "tsup src/index.ts --format cjs,esm --dts",
17
+ "build": "tsup index.ts --format cjs,esm --dts",
18
18
  "cleanBuild": "rm -rf dist"
19
19
  },
20
20
  "dependencies": {
@@ -34,4 +34,7 @@
34
34
  "main": "dist/index.js",
35
35
  "module": "dist/index.mjs",
36
36
  "types": "dist/types/index.d.ts"
37
+
38
+
39
+
37
40
  }
@@ -1,5 +1,7 @@
1
1
  import {StateObject} from "../stateObject";
2
2
  import {ValidState} from "../implementations/validState";
3
+ import {useState} from "react";
4
+ import {useStateObject} from "./useStateObject";
3
5
 
4
6
  /**
5
7
  * Hook that maps each element in an array within a StateObject to a new StateObject,
@@ -30,4 +32,19 @@ export function useRemapArray<T>(state: StateObject<T[]>): StateObject<T>[] {
30
32
  }
31
33
 
32
34
  return result // Return the array of StateObjects representing each element.
33
- }
35
+ }
36
+
37
+
38
+ /**
39
+ * Hook that takes an array of StateObjects and returns a new StateObject containing that array,
40
+ * allowing for updates to the entire array while keeping it synchronized within a single StateObject.
41
+ *
42
+ * @template T - The type of the elements in the array.
43
+ * @param states - The array of StateObjects.
44
+ * @returns A new StateObject containing the array of StateObjects, allowing for updates to the whole array.
45
+ */
46
+ export function useArrayState<T>(states: StateObject<T>[]): StateObject<T[]> {
47
+
48
+ return useStateObject(states.filter(state => state.hasValue).map(state => state.value));
49
+
50
+ }
package/tsconfig.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "ESNext", // Para exportar módulos ES6
4
- "target": "ESNext", // Para tener soporte de sintaxis moderna
5
- "declaration": true, // Para generar archivos de tipo .d.ts
6
- "declarationDir": "dist/types", // Para poner los archivos .d.ts en un directorio separado
7
- "outDir": "dist", // Para compilar el código en dist/
8
- "moduleResolution": "Node", // Para resolución de módulos similar a Node.js
9
- "esModuleInterop": true, // Para interoperabilidad con módulos CommonJS
10
- "strict": true // Para que TypeScript sea más estricto en el tipo de los archivos
3
+ "module": "ESNext",
4
+ "target": "ESNext",
5
+ "declaration": true,
6
+ "declarationDir": "dist/types",
7
+ "outDir": "dist",
8
+ "moduleResolution": "Node",
9
+ "esModuleInterop": true,
10
+ "strict": true
11
11
  },
12
12
  "include": [
13
- "src/**/*"
13
+ "src/**/*",
14
+ "index.ts"
14
15
  ]
15
- }
16
+ }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- export * from "./hooks/useFieldState";
2
- export * from "./hooks/useElementState";
3
- export * from "./hooks/useEmptyState";
4
- export * from "./hooks/useFieldState";
5
- export * from "./hooks/useRemapArray";
6
- export * from "./hooks/useStateObject";
7
- export * from "./stateObject";
8
-
9
-