-
Notifications
You must be signed in to change notification settings - Fork 47k
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
useImperativeHandle callback never called (when rendering w/ enzyme) #15054
Comments
You want: const Form = React.forwardRef((props, ref) => {
React.useImperativeHandle(ref, () => {
debugger;
return {
setErrors: () => {},
};
});
}) Don't miss In the future might make this unnecessary but we can't yet because that would have been a breaking change. |
@gaearon that is there, just on a separate line
or in the linked codesanbox example
I'm also thinking this might just be an enzyme issue, but not quite sure. Maybe something that enzyme is doing is causing react to not run that callback function? |
I noticed that when executed through It looks like this comes from react's
The initial I suspect this may have something to do with how enzyme is wrapping components, but debugging
|
Oops, missed that. |
If this only happens with Enzyme you'll want to file it with Enzyme. If it turns out that it's due to React I'd be happy to look into it. |
Followed the chain and it looks like workarounds/fix existed on the enzyme side, and it's not to do with React. Closing this issue. |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I have the code:
When I use the component, the callback passed to
useImperativeHandle
is never called. (The debugger statement is never hit).The code that I have using the component is:
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
https://codesandbox.io/s/v8rqy75mn5
What is the expected behavior?
Callback should be called and returned value should be used as the ref.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The text was updated successfully, but these errors were encountered: