I want to validate my input before passing it to onChange function from react-hook-form. Especially for input case like only accept number. I just tried with this snippet below, but I figure out if there are another better way.
<Controller
control={control}
name="nik"
rules={PERSONAL_INFORMATION_FORM_SCHEMA.nik}
render={({ field }) => (
<TextField
{...field}
error={!!errors?.nik}
helperText={errors.nik?.message}
id="nik"
name="nik"
placeholder={t("personalInformationInputIDNumberPlaceholder")}
type="text"
inputProps={{
pattern: "[0-9]*",
maxLength: 16
}}
onChange={event => field.onChange(validateInput(event))}
/>
)}
/>