-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
Unstable return reference of generated hook when using a custom mutator hook. #1359
Comments
Hi guys, I think this merge broke something, as the useCallback is not imported into the generated files which are affected by a custom axios instance.
Here is my orval.config.ts:
If you want to, I could also add another issue, but I guess it is hardly related to this one. It is working with version 6.25.0 |
Hmmm I am not having that issue with 7.1.0? You can see my generated code here and it has |
I updated to 7.1.0 and the error is still there. I will try to recreate a minimal example with our usecase to provide you more information. |
So here is my minimal example to reproduce this. I guess it has something todo with the tag dependent instance. I need a custom instance in my project for some tags to set some headers but only for this specific request. So I don't want to use an interceptor for this one. api.yaml:
orval.config.ts
The custom instance:
|
I would open a new ticket since this is a specific use case failing. |
What are the steps to reproduce this issue?
First of all, thanks for building Orval. We use it for quite a few projects 👍 .
One can generate endpoints with a custom mutator hook, for example:
https://github.com/anymaniax/orval/blob/4cfb246ce5f1816a9c809f96d9d2f2c5a80eac4a/samples/react-query/hook-mutator/endpoints.ts#L36-L38
What happens?
The reference returned by the generated
useListPetsHook
isn't stable: it changes on every render cycle.What were you expecting to happen?
I would have expected the following:
Now, the
useListPetsHook
will return the same reference on subsequent calls (given that youruseCustomInstance
doesn't change of course).A stable reference is useful when one uses memoization downstream, and the result of the
useListPetsHook
is part of auseMemo
oruseCallback
call in user-land code.The text was updated successfully, but these errors were encountered: