(
props: Props<TFieldValues>
)
| 62 | }; |
| 63 | |
| 64 | export 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 | |
| 88 | const getArraySource = (source: string) => |
| 89 | source.lastIndexOf('.') > 0 && ArraySourceRegex.test(source) |
nothing calls this directly
no test coverage detected