vendredi 13 septembre 2019

Mix redux and direct API Service calls?

I have a fairly large, complex React/Redux application. Up until recently, all of my API interaction has been handled via Redux actions. (Yay, consistency!) However, I had a case where we simply wanted to echo the raw results of an API call to the user in a new browser window. There is no need to touch global state at all, so it seemed like overkill (or even misuse?) to use the Redux architecture for this.

I still wanted to keep my component "dumb", so I settled on moving the API call to a "service" with a direct fetch call, to separate concerns without the Redux overhead.

It smells a bit that now, sometimes data is fetched and supplied via Redux, sometimes via services. (Boo, inconsistency!) Before going too far down this road, I wanted to see what others suggest.

My question is basically:

1) If you use Redux, should you use it for all API interaction, even if global state isn't involved? 2) If not, what is/are the best practice patterns for these kinds of API calls?

Hope the question made sense. Sorry if this has been asked and answered. I've done quite a bit of googling on this and came up pretty empty.

Aucun commentaire:

Enregistrer un commentaire