DEV Community

Ismail PE
Ismail PE

Posted on

Multiple api calls even for single saga action?

I was facing this issue in my React app and I could not find the exact reason in internet. There were many hacks and solutions for the same symptom, but nothing worked for me. Finally i solved it by correcting a mistake in code. So thought of posting it here.

I had an action which fetches a data via api call. There were other actions also defined inside same saga file. And this saga was used in multiple containers. Whenever i navigate between these containers, and call any action from this saga, there were multiple api calls triggered. But saga was called only once.

While injecting the saga, I was using different key names inside different containers for the same saga. Saga was supposed to automatically ignore the duplicate actions. But since the key was different, it considered all the calls as unique.

I used same key for this saga in all the containers where this was injected. So simple.

It was totally my mistake to use different keys. But i found same question in forums and github issues. So may be this would help someone to solve the issue or rule out this reason for the symptom.

Thank you.

Top comments (1)

hithesh__k profile image

Thanks for sharing this solution! It cleared up my confusion about resolving multiple API calls within a saga action. I appreciate you helping out the community.