react-state-monad 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/index.ts +1 -1
- package/package.json +9 -6
- package/src/hooks/useRemapArray.ts +18 -1
- package/tsconfig.json +11 -10
package/index.ts
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-state-monad",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.
|
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,8 +14,8 @@
|
|
14
14
|
],
|
15
15
|
"scripts": {
|
16
16
|
"validateTypes": "tsc --noEmit",
|
17
|
-
"build": "tsup
|
18
|
-
"cleanBuild"
|
17
|
+
"build": "tsup index.ts --format cjs,esm --dts",
|
18
|
+
"cleanBuild": "rm -rf dist"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
21
|
"react": "^19.0.0"
|
@@ -31,7 +31,10 @@
|
|
31
31
|
"url": "https://github.com/alvmivan"
|
32
32
|
},
|
33
33
|
"license": "GPL-3.0",
|
34
|
-
"main": "dist/index.js",
|
35
|
-
"module": "dist/index.mjs",
|
36
|
-
"types": "dist/types/index.d.ts"
|
34
|
+
"main": "dist/index.js",
|
35
|
+
"module": "dist/index.mjs",
|
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",
|
4
|
-
"target": "ESNext",
|
5
|
-
"declaration": true,
|
6
|
-
"declarationDir": "dist/types",
|
7
|
-
"outDir": "dist",
|
8
|
-
"moduleResolution": "Node",
|
9
|
-
"esModuleInterop": true,
|
10
|
-
"strict": true
|
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
|
+
}
|