11import React from 'react' ;
22
33import _ from 'lodash' ;
4- import { useForm } from 'react-final-form' ;
4+ import { useFormState } from 'react-final-form' ;
55
66import { DynamicFieldStore , FieldObjectValue , FieldValue , ValidateError } from '../types' ;
77import { transformArrIn } from '../utils' ;
88
99export const useStore = ( name : string ) => {
10- const form = useForm ( ) ;
10+ const formState = useFormState ( ) ;
1111 const firstRenderRef = React . useRef ( true ) ;
1212 const [ store , setStore ] = React . useState < DynamicFieldStore > ( ( ) => {
1313 const values : FieldObjectValue = transformArrIn ( {
14- [ name ] : _ . get ( form . getState ( ) . values , name ) ,
14+ [ name ] : _ . get ( formState . values , name ) ,
1515 } ) ;
1616
1717 const initialValue = transformArrIn ( {
18- [ name ] : _ . get ( form . getState ( ) . initialValues , name ) ,
18+ [ name ] : _ . get ( formState . initialValues , name ) ,
1919 } ) ;
2020
2121 return {
@@ -26,7 +26,7 @@ export const useStore = (name: string) => {
2626 } ;
2727 } ) ;
2828
29- const submitFailed = form . getState ( ) . submitFailed ;
29+ const submitFailed = formState . submitFailed ;
3030
3131 const tools = React . useMemo (
3232 ( ) => ( {
@@ -54,11 +54,11 @@ export const useStore = (name: string) => {
5454 React . useEffect ( ( ) => {
5555 if ( ! firstRenderRef . current ) {
5656 const values : FieldObjectValue = transformArrIn ( {
57- [ name ] : _ . get ( form . getState ( ) . values , name ) ,
57+ [ name ] : _ . get ( formState . values , name ) ,
5858 } ) ;
5959
6060 const initialValue = transformArrIn ( {
61- [ name ] : _ . get ( form . getState ( ) . initialValues , name ) ,
61+ [ name ] : _ . get ( formState . initialValues , name ) ,
6262 } ) ;
6363
6464 setStore ( {
0 commit comments