- Improve type-safety of
useCondition([...paths], conditions, getValues, control)
hook by narrowingpaths
to only field paths associated withconditions
, not any field path associated with the form. This improves editor autocompletion and type safety. - If a path is ever provided to
useCondition()
that is is not able to find a condition for, log a warning in the console. This should always be accompanied by a type error (above), but is a good safeguard so thatuseCondition()
never fails silently.
No changes in functionality.
- Fix NextJS import error (
Module not found: Default condition should be last one
) by tweakingpackage.json
's "extends" property.
First stable release! No functionality changes.
- Publish JS to NPM without minification to make debugging easier downstream.
- Add
useConditionalForm()
hook (drop-in replacement foruseForm()
that callspruneHiddenFields()
before validation) - Rename
useConditionalLogic()
->useCondition()
for brevity - Swap order of
pruneHiddenFields()
parameters (passgetValues
first)
- Fix bug where deeply nested values weren't pruned
- Fix bug where pruning within an array converted the array to an object
- Stop recommending pruning of valid form submission (since pruning already happens in resolver before validation)
- Have
useConditionalLogic()
return array (same as React Hook Form'suseWatch()
), instead of an object. Makes it easier to destructure deeply nested conditional values, e.g.
Before
// Before (returns object)
const { 'guests.0.wine': showWineField } = useConditionalLogic(
['guests.0.wine'],
conditions,
getValues,
control
);
// After (returns array)
const [showWineField] = useConditionalLogic(
['guests.0.wine'],
conditions,
getValues,
control
);
- Stop using
JSON.stringify()
to clone form data before pruning, since form data may not be fully serializable (user could stick anything in there). Instead, use newdeleteByPathWithoutMutation()
utility to prune values without mutation
First working draft of library!
- Expose
useConditionalLogic()
hook - Expose
pruneHiddenFields()
util