-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hooks: useImperativeHandle is preventing the default behaviour of useRef hook #2893
Comments
Not only data but we also got access to useful methods like So it would be nice if you'd expose all these methods also with |
I am wondering if |
OK I just upgraded 7.2.1 to 8.2.0 and I ran into this same issue. I was using |
Describe the bug
Since the transition from Class components to Hook based components, the access to the methods of a component has been handled with the
useImperativeHandle
hook. Example 1, Example 2, etc.This hook, instead of adding methods to the ref of components, has been replacing the ref completly, blocking the default behaivour of the
useRef
hook, accesing the dom element. In V7 we would also get access to the component props which gives the developer a lot of flexibility and useful state data.This issue needs two codesandboxes (SEE CONSOLE LOG):
V7: https://codesandbox.io/s/exciting-sound-6xncl2?file=/src/demo/AutoCompleteDemo.js
V8: https://codesandbox.io/s/nervous-shtern-fyhs9h?file=/src/demo/AutoCompleteDemo.js
Reproducer
https://codesandbox.io/s/nervous-shtern-fyhs9h?file=/src/demo/AutoCompleteDemo.js
PrimeReact version
8.1.0
React version
18.x
Language
ALL
Build / Runtime
Create React App (CRA)
Browser(s)
No response
Steps to reproduce the behavior
useRef
hook.ref.current
with auseEffect
hook.Expected behavior
When using a
useRef
hook and assigning the ref to a component, I expect to get access to the dom element (and its props, having used primereact V7).The text was updated successfully, but these errors were encountered: