-
Notifications
You must be signed in to change notification settings - Fork 4
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
useApi doesn't provide a loader instance for usage in useLoader #34
Comments
Hi! The intent of these hooks was to mimic something like Having said that, I'm not a fan of this approach and would be happy to discuss alternative solutions -- including the hooks themselves. Further, the docs are very barebones and are in dire need of a refresh. Happy to take suggestions. |
By the way, there's another topic related to the loader's state: error responses. An obstacle I encountered during my experiments with the library is that there's no way to access API error details from the component. To be more specific, let's consider form validation error responses. Yes, I can manage the error inside my effect handler, but generally, I'm not fond of the idea of putting too much UI state into the Redux store. I notice that you already have some relevant experience in developing using saga-query. How do you handle such cases? Do you simply put the validation into the store? |
There's a bunch of ways you can manage errors, but ultimately error messages and any associated meta data gets stored inside the loader (inside redux). If your API returns a common structure for API errors, you can a) create a custom middleware to attach the error data to Line 151 in fe762d6
Line 303 in fe762d6
Unfortunately this function doesn't allow users to provide |
saga-query/src/react.ts
Line 195 in fe762d6
Currently
useApi
doesn't provide a reference to theloader
, but rather all it's properties.saga-query/src/react.ts
Line 116 in fe762d6
Should we fix this exporting the
loader
instead of spreading it? It will be a breaking change.I would rather rewrite docs a little bit to point out that the loader must be first obtained using
useLoader(action)
hook.The text was updated successfully, but these errors were encountered: