Confirm password
Repeat-password fields with the same hook and matchWith.
Basic usage
There is no separate hook. Give the confirm field matchWith: matches is true, false, or null while the field is empty. Both values are compared after NFKC, like on the server.
Repeat the password.
rule
rule.validate always reads the latest matchWith, so the same object can go into register(). To re-check the confirm field when the password changes, see deps.
const password = useWatch({ control: form.control, name: "password" })
const { inputProps, rule } = useViraPassword({ matchWith: password })
<input {...inputProps} {...form.register("confirm", rule)} />
// "password.mismatch" when the values differ (an empty confirm fails too)Shared visibility
Each field has its own toggle. To show both at once, control them with one state:
const [visible, setVisible] = useState(false)
const shared = { visible, onVisibleChange: setVisible }
const passwordField = useViraPassword(shared)
const confirmField = useViraPassword({ ...shared, matchWith: password })