issue: Uncaught TypeError: fieldRef.focus is not a function error in React-hook-form setFocus with Reactstrap Input
See original GitHub issueVersion Number
7.36.1
Codesandbox/Expo snack
https://codesandbox.io/s/gallant-voice-vqqi47?file=/src/App.js
Steps to reproduce
- In the sandbox, don’t fill up anything and just click submit.
More details in my stackoverflow question: https://stackoverflow.com/questions/73931883/uncaught-typeerror-fieldref-focus-is-not-a-function-error-in-react-hook-form-se
Expected behaviour
Supposedly, I want it to focus to the first input that errors but it crashes instead.
What browsers are you seeing the problem on?
Chrome
Relevant log output
react-dom.development.js:22839 Uncaught TypeError: fieldRef.focus is not a function
at setFocus (createFormControl.ts:1226:1)
at usePersonalAccountForm.ts:73:1
at commitHookEffectListMount (react-dom.development.js:23150:1)
at commitPassiveMountOnFiber (react-dom.development.js:24926:1)
at commitPassiveMountEffects_complete (react-dom.development.js:24891:1)
at commitPassiveMountEffects_begin (react-dom.development.js:24878:1)
at commitPassiveMountEffects (react-dom.development.js:24866:1)
at flushPassiveEffectsImpl (react-dom.development.js:27039:1)
at flushPassiveEffects (react-dom.development.js:26984:1)
at commitRootImpl (react-dom.development.js:26935:1)
setFocus @ createFormControl.ts:1226
(anonymous) @ usePersonalAccountForm.ts:73
commitHookEffectListMount @ react-dom.development.js:23150
commitPassiveMountOnFiber @ react-dom.development.js:24926
commitPassiveMountEffects_complete @ react-dom.development.js:24891
commitPassiveMountEffects_begin @ react-dom.development.js:24878
commitPassiveMountEffects @ react-dom.development.js:24866
flushPassiveEffectsImpl @ react-dom.development.js:27039
flushPassiveEffects @ react-dom.development.js:26984
commitRootImpl @ react-dom.development.js:26935
commitRoot @ react-dom.development.js:26682
performSyncWorkOnRoot @ react-dom.development.js:26117
flushSyncCallbacks @ react-dom.development.js:12042
(anonymous) @ react-dom.development.js:25651
react_devtools_backend.js:4026 The above error occurred in the <PersonalAccountPage> component:
at PersonalAccountPage (https://localhost:3000/static/js/src_pages_CreateAccount_PersonalAccount_PersonalAccountPage_tsx.chunk.js:130:81)
at RenderedRoute (https://localhost:3000/static/js/bundle.js:61948:5)
at Outlet (https://localhost:3000/static/js/bundle.js:62303:26)
at Suspense
at RouteWrapper (https://localhost:3000/static/js/bundle.js:1649:81)
at RenderedRoute (https://localhost:3000/static/js/bundle.js:61948:5)
at Routes (https://localhost:3000/static/js/bundle.js:62397:5)
at div
at div
at CreateAccountRoutes
at RenderedRoute (https://localhost:3000/static/js/bundle.js:61948:5)
at Outlet (https://localhost:3000/static/js/bundle.js:62303:26)
at Suspense
at RouteWrapper (https://localhost:3000/static/js/bundle.js:1649:81)
at RenderedRoute (https://localhost:3000/static/js/bundle.js:61948:5)
at Routes (https://localhost:3000/static/js/bundle.js:62397:5)
at main
at Layout (https://localhost:3000/static/js/bundle.js:2033:5)
at Router (https://localhost:3000/static/js/bundle.js:62328:15)
at BrowserRouter (https://localhost:3000/static/js/bundle.js:60549:5)
at div
at App (https://localhost:3000/static/js/bundle.js:1347:51)
at Provider (https://localhost:3000/static/js/bundle.js:57681:5)
at r (https://localhost:3000/static/js/bundle.js:56945:19)
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.
overrideMethod @ react_devtools_backend.js:4026
logCapturedError @ react-dom.development.js:18687
update.callback @ react-dom.development.js:18720
callCallback @ react-dom.development.js:13923
commitUpdateQueue @ react-dom.development.js:13944
commitLayoutEffectOnFiber @ react-dom.development.js:23391
commitLayoutMountEffects_complete @ react-dom.development.js:24688
commitLayoutEffects_begin @ react-dom.development.js:24674
commitLayoutEffects @ react-dom.development.js:24612
commitRootImpl @ react-dom.development.js:26823
commitRoot @ react-dom.development.js:26682
performSyncWorkOnRoot @ react-dom.development.js:26117
flushSyncCallbacks @ react-dom.development.js:12042
(anonymous) @ react-dom.development.js:25651
react-dom.development.js:12056 Uncaught TypeError: fieldRef.focus is not a function
at setFocus (createFormControl.ts:1226:1)
at usePersonalAccountForm.ts:73:1
at commitHookEffectListMount (react-dom.development.js:23150:1)
at commitPassiveMountOnFiber (react-dom.development.js:24926:1)
at commitPassiveMountEffects_complete (react-dom.development.js:24891:1)
at commitPassiveMountEffects_begin (react-dom.development.js:24878:1)
at commitPassiveMountEffects (react-dom.development.js:24866:1)
at flushPassiveEffectsImpl (react-dom.development.js:27039:1)
at flushPassiveEffects (react-dom.development.js:26984:1)
at commitRootImpl (react-dom.development.js:26935:1)
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created a year ago
- Comments:25 (9 by maintainers)
Top Results From Across the Web
fieldRef.focus is not a function error in React-hook-form ...
If you ever encounter this error, this was caused by React's Strict Mode in dev environment. It means that this error wont occur...
Read more >useForm - setFocus - Simple React forms validation
This method will allow users to programmatically focus on input. Make sure input's ref is registered into the hook form. Props. Name, Type,...
Read more >react-dom.development.js:18687 the above error occurred in ...
React : Uncaught TypeError: Cannot read properties of undefined (reading ... is not a function error in React-hook-form setFocus with Reactstrap Input#9126.
Read more >How to autofocus using React Hooks - LogRocket Blog
In this article, we'll look at how to add autofocus to React input fields. Then, we will make our code reusable by turning...
Read more >react-hook-form setFocus error - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js. DashboardCtrl+Escape ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The issue is still there on version “react-hook-form”: “^7.39.4”,
Tried to pass error to Cleave components or Flatpickr and everytime an error is generated the focus method crashes the app giving this error:
Env
Only if I set “shouldFocusError” to false everything work fine.
*** relevant code ***
Components
working version: https://codesandbox.io/s/stupefied-mahavira-9s2ffl?file=/src/App.js