File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
frontend/packages/pydantic-forms/src/core/hooks Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ export * from './useLabelProvider';
5
5
export * from './usePydanticForm' ;
6
6
export * from './useGetConfig' ;
7
7
export * from './useGetValidationErrors' ;
8
+ export * from './useFieldDataStorage' ;
Original file line number Diff line number Diff line change
1
+ import { useMemo , useRef } from 'react' ;
2
+
3
+ export const useGetFieldDataStorage = ( ) => {
4
+ const fieldDataStorageRef = useRef < Map < string , Map < string , unknown > > > (
5
+ new Map ( ) ,
6
+ ) ;
7
+
8
+ const fieldDataStorage = useMemo (
9
+ ( ) => ( {
10
+ has : ( fieldId : string , key : string | number ) => {
11
+ if (
12
+ fieldDataStorageRef . current &&
13
+ fieldDataStorageRef . current . has ( fieldId )
14
+ ) {
15
+ const fieldStorage =
16
+ fieldDataStorageRef . current . get ( fieldId ) ;
17
+ return fieldStorage ?. has ( key . toString ( ) ) ?? false ;
18
+ }
19
+ return false ;
20
+ } ,
21
+ get : ( fieldId : string , key : string | number ) => {
22
+ const fieldData = fieldDataStorageRef ?. current ?. get ( fieldId ) ;
23
+ return fieldData ?. get ( key . toString ( ) ) ;
24
+ } ,
25
+ set : ( fieldId : string , key : string | number , value : unknown ) => {
26
+ fieldDataStorageRef . current . set (
27
+ fieldId ,
28
+ new Map ( [ [ key . toString ( ) , value ] ] ) ,
29
+ ) ;
30
+ } ,
31
+ delete : ( fieldId : string ) => {
32
+ if ( fieldDataStorageRef . current ?. has ( fieldId ) ) {
33
+ fieldDataStorageRef . current . delete ( fieldId ) ;
34
+ }
35
+ } ,
36
+ } ) ,
37
+ [ ] ,
38
+ ) ;
39
+
40
+ return { fieldDataStorage } ;
41
+ } ;
You can’t perform that action at this time.
0 commit comments