File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 1
- import { useState , useEffect , useRef } from 'react'
1
+ import { useState , useEffect , useRef , useCallback } from 'react'
2
2
import { createForm , formSubscriptionItems } from 'final-form'
3
3
4
4
export const all = formSubscriptionItems . reduce ( ( result , key ) => {
@@ -12,7 +12,19 @@ const useForm = ({ subscription, ...config }) => {
12
12
useEffect ( ( ) => form . current . subscribe ( setState , subscription || all ) , [
13
13
subscription
14
14
] )
15
- return { ...state , form : form . current }
15
+ const handleSubmit = useCallback ( event => {
16
+ if ( event ) {
17
+ if ( typeof event . preventDefault === 'function' ) {
18
+ event . preventDefault ( )
19
+ }
20
+ if ( typeof event . stopPropagation === 'function' ) {
21
+ event . stopPropagation ( )
22
+ }
23
+ }
24
+ return form . current . submit ( )
25
+ } , [ ] )
26
+
27
+ return { ...state , form : form . current , handleSubmit }
16
28
}
17
29
18
30
export default useForm
You can’t perform that action at this time.
0 commit comments