@@ -4,7 +4,6 @@ import { useFormContext, FieldValues } from 'react-hook-form';
44import get from 'lodash/get' ;
55import { useFormValues } from './useFormValues' ;
66import { useWrappedSource } from '../core' ;
7- import { useEvent } from '../util' ;
87
98/**
109 * Get the current (edited) value of the record from the form and pass it
@@ -68,26 +67,22 @@ export const FormDataConsumerView = <
6867 props : Props < TFieldValues >
6968) => {
7069 const { children, formData, source } = props ;
71- const [ result , setResult ] = React . useState < ReactNode > ( null ) ;
70+ let result ;
7271
7372 const finalSource = useWrappedSource ( source || '' ) ;
74- const render = useEvent ( children ) ;
7573
76- // Getting the result of the children function in a useEffect allows us to keep a stable reference to is
77- // with useEvent
78- React . useEffect ( ( ) => {
79- // Passes an empty string here as we don't have the children sources and we just want to know if we are in an iterator
80- const matches = ArraySourceRegex . exec ( finalSource ) ;
81- // If we have an index, we are in an iterator like component (such as the SimpleFormIterator)
82- if ( matches ) {
83- const scopedFormData = get ( formData , matches [ 0 ] ) ;
84- setResult ( render ( { formData, scopedFormData } ) ) ;
85- } else {
86- setResult ( render ( { formData } ) ) ;
87- }
88- } , [ finalSource , formData , render ] ) ;
74+ // Passes an empty string here as we don't have the children sources and we just want to know if we are in an iterator
75+ const matches = ArraySourceRegex . exec ( finalSource ) ;
8976
90- return result ;
77+ // If we have an index, we are in an iterator like component (such as the SimpleFormIterator)
78+ if ( matches ) {
79+ const scopedFormData = get ( formData , matches [ 0 ] ) ;
80+ result = children ( { formData, scopedFormData } ) ;
81+ } else {
82+ result = children ( { formData } ) ;
83+ }
84+
85+ return result === undefined ? null : result ;
9186} ;
9287
9388const ArraySourceRegex = new RegExp ( / .+ \. \d + $ / ) ;
0 commit comments