Is it possible to not expose fetch methods?
Richard87 opened this issue · comments
Hi!
We need React Context in our fetch (to get a valid auth token).
If fetchXXX is used directly this will not work. Is it possible to not expose those methods?
or even better, automatically add all as a api client hook:
const api = useApi()
api.fetchXYZ()
Hi,
You can use the context and fetcher files for this. Those files are only generated when they don't exists and meant to be tweak for this exact usecase
You can see an example here:
-
Retrieve the token from a custom react hook and expose it inside
fetcherOptions
-
Inject it in the fetch (as you can see, the fetcher is using the types from the custom hook)
To understand "the magic", you can have a look on the generated components:
Every components is calling this custom hook (that you can tweak) and send the result the fetcher (that you can also tweak)
Hi!
Thanks for the explanation, that helps a lot 🙏