Check if a value is empty: null, undefined, empty string, array, or object.
export function isEmpty(value: unknown): boolean {
if (value == null) return true;
if (typeof value === 'string') return value.trim() === '';
if (Array.isArray(value)) return value.length === 0;
if (typeof value === 'object') return Object.keys(value as object).length === 0;
return false;
}
Returns true for null, undefined, empty string, empty array, or empty object. Handles trimmed strings.
Validation, conditional rendering, or defaults.
if (isEmpty(form.errors)) submit();