ForwardRef issue when using <Controller>
See original GitHub issueDescribe the bug
After updating to 6.11.0 I am facing an issue when I am using <Controller>
To Reproduce Steps to reproduce the behavior:
- Go to ‘https://codesandbox.io/s/react-hook-form-controller-forked-drdv2?file=/package.json’
- Click on ‘open console’
- Scroll down to ‘…’
- Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Codesandbox link (Required) https://codesandbox.io/s/react-hook-form-controller-forked-drdv2?file=/package.json
Screenshots
If applicable, add screenshots to help explain your problem.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:15
- Comments:22 (8 by maintainers)
Top Results From Across the Web
React hook form v7 Function components cannot be given refs ...
So the issue is that I think that the {...register("name"}} line actually ... forwardRef() solves the problem when using Custom Components.
Read more >warning: function components cannot be given refs. attempts ...
8. As the warning states you cannot assign refs to functional components without the usage of forwardRef. In order to have access to...
Read more >ref prop should not be used on React function components
If the intention is to refer an inner element of the function component, you can use React.forwardRef() instead.
Read more >Circular Dependency - A progressive Node.js framework
An alternative to using forwardRef() is to refactor your code and use the ModuleRef class to retrieve a provider on one side of...
Read more >How to avoid circular dependencies in NestJS - LogRocket Blog
Learn about the issues caused by circular dependencies in Nestjs, ... Now, say we use the UserService as follows in the UserController class ......
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
@bluebill1049 this does not work when using the
as
prop of the ControllerI updated your example, you can see the error there
https://codesandbox.io/s/wandering-wood-bcmm7?file=/src/App.tsx
Controller
now hasref
prop for better focus management and accessibility. eg now React-Select works out the box with auto focus.https://codesandbox.io/s/focused-sammet-tr193
it’s best to wire up the
ref
yourself, eg: TextField could beinputRef
so we can focus that input when an error occurred, or you can omit thatref
prop.