@modular-forms/react
Version:
The modular and type-safe form library for React
20 lines (19 loc) • 615 B
JavaScript
import { removeInvalidNames } from './removeInvalidNames';
/**
* Returns a list with the names of all field arrays.
*
* @param form The form of the field arrays.
* @param shouldValid Whether to be valid.
*
* @returns All field array names of the form.
*/
export function getFieldArrayNames(form, shouldValid = true) {
// Get name of every field array
const fieldArrayNames = [...form.internal.fieldArrayNames.peek()];
// Remove invalid field array names
if (shouldValid) {
removeInvalidNames(form, fieldArrayNames);
}
// Return field array names
return fieldArrayNames;
}