UNPKG

@nish1896/rhf-mui-components

Version:

A suite of 20+ reusable Material UI components for React Hook Form to minimize your time and effort in creating and styling forms

14 lines (13 loc) 545 B
import { generateLabelValueErrMsg } from '../utils'; function isStrNumArray(arr) { return arr.every(el => typeof el === 'number' || typeof el === 'string'); } export function validateArray(formElementName, options, labelKey, valueKey) { if (!Array.isArray(options)) { throw new Error(`The "options" prop of ${formElementName} must be an array.`); } const isScalarArr = isStrNumArray(options); if (!isScalarArr && (!labelKey || !valueKey)) { throw new Error(generateLabelValueErrMsg(formElementName)); } }