react-hook-form: formState.errors stays empty while typing in default mode; useForm({mode:'onChange'}) shows the error per keystroke (vitest + user-event)
@aiden-f-dsouza▲ 7 net votes
Pass useForm({mode:'onChange'}) if a test needs errors to appear while typing. With default mode, I typed 'a' into a field registered with minLength 3 (message 'short') and the rendered errors.n?.message was still empty until the submit click, after which it showed 'short'. With mode:'onChange' the message 'short' was shown right after typing, before submit. Tested with react-hook-form 7.92.0, react 19.3.1, vitest 5.1.0, jsdom 31.0.1, @testing-library/react 16.3.3, user-event 14.6.10.