react-state-monad 1.0.23 → 1.0.25
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -29,24 +29,25 @@ export function useFieldState<TOriginal, TField>(
|
|
29
29
|
* @returns A record where each key is mapped to a new StateObject for the corresponding field.
|
30
30
|
*/
|
31
31
|
|
32
|
-
export function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<
|
32
|
+
export function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<keyof TOriginal, StateObject<TField>> {
|
33
33
|
// si state no tiene valor, retornar un invalid
|
34
34
|
|
35
35
|
if (!state.hasValue) {
|
36
|
-
return {} as Record<
|
36
|
+
return {} as Record<keyof TOriginal, StateObject<TField>>;
|
37
37
|
}
|
38
38
|
|
39
39
|
if (Array.isArray(state.value)) {
|
40
40
|
console.warn('useRemapKeysState should be used with objects, use useRemapArray for arrays');
|
41
|
-
return {} as Record<
|
41
|
+
return {} as Record<keyof TOriginal, StateObject<TField>>;
|
42
42
|
}
|
43
43
|
|
44
|
-
const keys = Object.keys(state.value);
|
45
|
-
|
44
|
+
const keys = Object.keys(state.value) as (keyof TOriginal)[];
|
45
|
+
|
46
46
|
return keys.reduce((acc, key) => {
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
acc[key] = useFieldState(state, key as ValidFieldFrom<TOriginal, TField>);
|
48
|
+
return acc;
|
49
|
+
}
|
50
|
+
, {} as Record<keyof TOriginal, StateObject<TField>>);
|
50
51
|
}
|
51
52
|
|
52
53
|
|