v1.0.9
Add new hooks
This release introduces useForm, an orchestrator for managing multiple fields with schema validation support, and useNotification, a reactive wrapper around the browser Notifications API. It also fixes DOM initialization bugs in useField affecting selects, textareas, and checkboxes, and repairs usePermission, whose change listener was attached to a target the event never reaches.
Features
useForm— added a hook to manage a whole form, keeping values in the DOM and exposingregister,handleSubmit,trigger,watch,reset, and per-fielddirty,touched,errors, andsubmittingstate, with an optionalresolverfor schema validation through zod, yup, or valibot.useField— moved validation rules into the hook options sorequired,min,max,minLength,maxLength,pattern, andvalidatecan be declared once at the call site, withregisterparams overriding them per element.usePermission— added anonChangecallback, available as a second argument or through the options object, so consumers can react to permission changes without watchingstate.useNotification— added a hook that wraps the browser Notifications API, exposingsupported,notification,trigger,show, andclose.useNotification— the current notification is closed once the tab becomes visible again, since the user has already seen whatever it announced.
Fixes
useField— the registerrefno longer reinitializes an element it has already seen, so a value chosen by the user survives rerenders instead of being reset to the initial value every time the callback ref is reattached.useField— selects and textareas are now initialized throughvalueinstead ofdefaultValue, which selects have no DOM property for and which React overwrites on textareas during reconciliation.useField— thedirtystate and validation rules now readcheckedfor checkboxes and radios instead ofvalue, which always returned the stringonand made checkboxes permanently dirty while leavingrequiredunenforced.usePermission— thechangelistener is now attached to thePermissionStatusreturned bynavigator.permissions.query()rather than towindow, which the event never reaches, so external permission changes are finally reflected instate.usePermission— the listener is removed on unmount and whenever the permission name changes, instead of leaking for the lifetime of the page.usePermission—queryno longer throws whennavigator.permissionsis unavailable, returningpromptinstead.