From e4c59b89892acc15ed6199fcba887f0d5101e2e4 Mon Sep 17 00:00:00 2001 From: Micah Engle-Eshleman Date: Fri, 10 Nov 2023 11:40:36 -0700 Subject: [PATCH] Add example further up on page --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c8021b7..a8216b4 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,15 @@ A tiny library that makes it easy to define conditional logic in one place, expo ## Features -- Define conditional logic (whether to show/hide fields) in a single typed object +- Define conditional logic (whether to show/hide fields) in a single typed object, e.g. + ```ts + const conditions = { + // Show "Other Caterer" field if "Other" option is selected + otherCaterer: getValues => getValues('caterer') === 'Other', + // Show wine pairing options for guests over 21 + ['guests.#.wine']: getValues => getValues('guests.#.age') >= 21, + }; + ``` - A single condition can be defined for all indices in an array by using `#` as a wildcard (e.g. `guests.#.email`) - `useConditionalForm()` drop-in replacement for `useForm()` prunes hidden field values before validation. This way you can track hidden field values with `shouldUnregister = false` for better UX but not have to worry about hidden fields showing up in `errors` or preventing submission entirely.