Skip to content

Instantly share code, notes, and snippets.

@dazuaz
dazuaz / form-extensions.tsx
Last active September 1, 2023 02:32
Utility to add conditional fields to react hook forms and Zod resolvers
type Rule<T> = {
field: keyof T;
operator: 'is' | 'isNot';
value: T[keyof T];
};
type Condition<T> = {
type: 'show' | 'hide';
rulesMatch: 'any' | 'all';
rules: Rule<T>[];