-
Notifications
You must be signed in to change notification settings - Fork 109
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
Helper component to handle CRUD API operations #94
Comments
roman from Red Badger Team in the React London Slack group, was nice to give me this example. I'm just pasting it for your reference:
|
I am not sure in which context you would need to do this. Could you elaborate on the purpose of doing it this way and how we could support this in redux-json-api? |
Abstracting all the API related methods into a Helper module/component would free other components in the app from the repetition of having to call all the time setEndpointHost, setEndpointPath, setAccessToken, setHeader... That's a lot of config required for each API request, thus it's better to write it ONCE in one place rather than everytime we need to make an API request. Maybe I'm missing something, but considering that in a React app, the order in which components mount is not really known or can be easily arranged, I needed to call all these previously mentioned methods prior to making the API request. |
You don't need to dispatch the configuring actions for each API request. The configuration is stored in state and will be used automatically for all requests. |
@egeriis And in which file do you usually set the configuration to make sure it runs before any other component? If I put it in the On the other hand, I cannot put it before my
It would help a lot if you specify in the |
@gazpachu In your case, dispatching those actions in |
How can I make a
Helpers
component to handle CRUD API methods and other utilities? I could use a regular component but I don’t need therender
methodI need to access
this.props.dispatch
so usingmodule.exports
doesn’t work well for that, because when I passthis.props.dispatch
as an argument to readAPI, I getdispatch is not a function(…)
:Helpers.jsx:
This is how I would call it:
The text was updated successfully, but these errors were encountered: