useViraMask()
Mask multiple fields with one hook. Schema field names match form fields.
Basic usage
rawValue: -
value: -
Schema
Three forms are valid for each field:
- Preset string:
{ phone: "phone" } - Options object:
{ amount: { currency: { decimalSeparator: ",", thousandSeparator: ".", symbol: "₺" } } } - Preset + override:
{ card: { preset: "card", onCardTypeChange: fn } }
See the examples page for all presets. For masks from scratch, see custom mask.
Return value
useViraMask() returns a MaskField for each key in the schema. Strip rawValue before spreading so it never lands on the DOM - value stays in inputProps: const { rawValue, ...inputProps } = phone
value: formatted (display) valuerawValue: raw value stored in the formref,name,onChange,onBlur,onFocus,onKeyDowntype,inputMode,autoCompletearia-invalid,aria-describedby,title
React Hook Form
- Each field is
registered; validation runs undervalidate.maskFormat. setValuewrites the raw value to the form (shouldValidate/shouldDirty/shouldTouch).- Validation runs only when
validate: trueand the value is not empty; details on the validation page.
