1
- import { useState , useEffect , useRef } from 'react'
2
1
import { fieldSubscriptionItems } from 'final-form'
2
+ import { useEffect , useRef , useState } from 'react'
3
3
4
4
export const all = fieldSubscriptionItems . reduce ( ( result , key ) => {
5
5
result [ key ] = true
@@ -21,8 +21,11 @@ const eventValue = event => {
21
21
22
22
const useField = ( name , form , validate , subscription = all ) => {
23
23
const autoFocus = useRef ( false )
24
+ const validatorRef = useRef ( undefined )
24
25
const [ state , setState ] = useState ( { } )
25
26
27
+ validatorRef . current = validate
28
+
26
29
const deps = subscriptionToInputs ( subscription )
27
30
useEffect (
28
31
( ) =>
@@ -38,12 +41,12 @@ const useField = (name, form, validate, subscription = all) => {
38
41
subscription ,
39
42
validate
40
43
? {
41
- getValidator : ( ) => validate
44
+ getValidator : ( ) => validatorRef . current
42
45
}
43
46
: undefined
44
47
) ,
45
48
// eslint-disable-next-line react-hooks/exhaustive-deps
46
- [ name , form , validate , ...deps ]
49
+ [ name , form , ...deps ]
47
50
)
48
51
let { blur, change, focus, value, ...meta } = state
49
52
delete meta . name // it's in input
0 commit comments