MCPcopy
hub / github.com/marmelab/react-admin / FormDataConsumerView

Function FormDataConsumerView

packages/ra-core/src/form/FormDataConsumer.tsx:64–86  ·  view source on GitHub ↗
(
    props: Props<TFieldValues>
)

Source from the content-addressed store, hash-verified

62};
63
64export const FormDataConsumerView = <
65 TFieldValues extends FieldValues = FieldValues,
66>(
67 props: Props<TFieldValues>
68) => {
69 const { children, formData, source } = props;
70 let result;
71
72 const finalSource = useWrappedSource(source || '');
73
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 arraySource = getArraySource(finalSource);
76
77 // If we have an index, we are in an iterator like component (such as the SimpleFormIterator)
78 if (arraySource) {
79 const scopedFormData = get(formData, arraySource);
80 result = children({ formData, scopedFormData });
81 } else {
82 result = children({ formData });
83 }
84
85 return result === undefined ? null : result;
86};
87
88const getArraySource = (source: string) =>
89 source.lastIndexOf('.') > 0 && ArraySourceRegex.test(source)

Callers

nothing calls this directly

Calls 4

useWrappedSourceFunction · 0.90
getArraySourceFunction · 0.85
childrenFunction · 0.85
getFunction · 0.50

Tested by

no test coverage detected