@@ -17,12 +17,14 @@ export interface FormProviderProps {
17
17
18
18
export interface FormContextProps extends FormProviderProps {
19
19
triggerFormChange : ( name : string , changedFields : FieldData [ ] ) => void ;
20
- registerForm : ( name : string , form : FormInstance ) => ( ) => void ;
20
+ registerForm : ( name : string , form : FormInstance ) => void ;
21
+ unregisterForm : ( name : string ) => void ;
21
22
}
22
23
23
24
const FormContext = React . createContext < FormContextProps > ( {
24
25
triggerFormChange : ( ) => { } ,
25
- registerForm : ( ) => ( ) => { } ,
26
+ registerForm : ( ) => { } ,
27
+ unregisterForm : ( ) => { } ,
26
28
} ) ;
27
29
28
30
const FormProvider : React . FunctionComponent < FormProviderProps > = ( {
@@ -38,7 +40,7 @@ const FormProvider: React.FunctionComponent<FormProviderProps> = ({
38
40
< FormContext . Provider
39
41
value = { {
40
42
...formContext ,
41
- validateMessages,
43
+ validateMessages : { ... formContext . validateMessages , ... validateMessages } ,
42
44
43
45
// =========================================================
44
46
// = Global Form Control =
@@ -50,6 +52,8 @@ const FormProvider: React.FunctionComponent<FormProviderProps> = ({
50
52
forms : formsRef . current ,
51
53
} ) ;
52
54
}
55
+
56
+ formContext . triggerFormChange ( name , changedFields ) ;
53
57
} ,
54
58
registerForm : ( name , form ) => {
55
59
if ( name ) {
@@ -59,11 +63,14 @@ const FormProvider: React.FunctionComponent<FormProviderProps> = ({
59
63
} ;
60
64
}
61
65
62
- return ( ) => {
63
- const newForms = { ...formsRef . current } ;
64
- delete newForms [ name ] ;
65
- formsRef . current = newForms ;
66
- } ;
66
+ formContext . registerForm ( name , form ) ;
67
+ } ,
68
+ unregisterForm : name => {
69
+ const newForms = { ...formsRef . current } ;
70
+ delete newForms [ name ] ;
71
+ formsRef . current = newForms ;
72
+
73
+ formContext . unregisterForm ( name ) ;
67
74
} ,
68
75
} }
69
76
>
0 commit comments