React Hook Form integration
Use NumoraInput with React Hook Form through its Controller component.
numora-react does not depend on react-hook-form. Install it in your project yourself.
Controller pattern
Spread field onto NumoraInput. It forwards name, value, onChange, onBlur, ref and disabled.
In onChange, React Hook Form reads e.target.value. On NumoraInput that is the raw value, so the form stores "1234.5" in every locale. onBlur tracks the touched state. ref focuses the field on a validation error.
Give the field a string in defaultValues, so it is controlled from the first render.
A form with one Controller field. setValue() updates the input. The live field shows the input alone, without the form.
Validation errors
Show the message from fieldState.error. Validate with a validate function that works on the string. React Hook Form's min and max rules convert the value to a JavaScript number, which loses precision on long amounts.
The same goes for a schema resolver. Keep the amount a string in the schema, such as Zod's z.string(). z.coerce.number() converts it to a JavaScript number.
Reusable field
To use the field in several forms, wrap it once with useController. The wrapper gives name, control, rules and disabled to React Hook Form, and passes every other prop to NumoraInput. Set the initial value in the form's defaultValues.
The onChange event carries both strings. If you write the handler yourself, pass the raw value: onChange={(e) => field.onChange(e.target.value)}.
e.target.valueis the raw value,"1000.50"in every localee.target.formattedValueis the display value,"1,000.50"in en-US
Complete example
A swap form with Max and Half buttons. Both write the amount with setValue(), as a string.
Try it with any locale
A live form built with React Hook Form. Switch the locale and compare what the field shows with what the form holds. The form state is the same raw value in every locale.
. as the decimal mark) in every locale. Try typing, pasting a number copied from another app, and switching the locale mid-edit.Why not register?
Don't spread register('amount') onto NumoraInput. register reads the value from the DOM node, and the DOM node holds the display value. The form stores "1,234.5", or "1.234,5" in de-DE, where you wanted "1234.5".
Writing is worse. setValue() and reset() put their string straight into the input, past Numora. In a de-DE field, setValue('amount', '1234.5') shows 1234.5. Type a 6 after it and the field reads 123.456, because the dot was taken for a thousand separator. Use Controller.