Skip to content

Commit

Permalink
Revert #10417 as it causes issues with StackedFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Jan 17, 2025
1 parent 6b56876 commit 3f6a312
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions packages/ra-core/src/form/FormDataConsumer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useFormContext, FieldValues } from 'react-hook-form';
import get from 'lodash/get';
import { useFormValues } from './useFormValues';
import { useWrappedSource } from '../core';
import { useEvent } from '../util';

/**
* Get the current (edited) value of the record from the form and pass it
Expand Down Expand Up @@ -68,26 +67,22 @@ export const FormDataConsumerView = <
props: Props<TFieldValues>
) => {
const { children, formData, source } = props;
const [result, setResult] = React.useState<ReactNode>(null);
let result;

const finalSource = useWrappedSource(source || '');
const render = useEvent(children);

// Getting the result of the children function in a useEffect allows us to keep a stable reference to is
// with useEvent
React.useEffect(() => {
// 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
const matches = ArraySourceRegex.exec(finalSource);
// If we have an index, we are in an iterator like component (such as the SimpleFormIterator)
if (matches) {
const scopedFormData = get(formData, matches[0]);
setResult(render({ formData, scopedFormData }));
} else {
setResult(render({ formData }));
}
}, [finalSource, formData, render]);
// 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
const matches = ArraySourceRegex.exec(finalSource);

return result;
// If we have an index, we are in an iterator like component (such as the SimpleFormIterator)
if (matches) {
const scopedFormData = get(formData, matches[0]);
result = children({ formData, scopedFormData });
} else {
result = children({ formData });
}

return result === undefined ? null : result;
};

const ArraySourceRegex = new RegExp(/.+\.\d+$/);
Expand Down

0 comments on commit 3f6a312

Please sign in to comment.