praful
praful

Reputation: 51

Why we need to call api in redux thunk or saga why not in component?

when we need to some data through api and we use redux in react that time we use redux-thunk or saga but my qustion is it also possible through component useEffect hooks, we call api in useEffect and then pass data using action in redux store.

Upvotes: 1

Views: 918

Answers (1)

ridvanaltun
ridvanaltun

Reputation: 3020

In short, using redux-thunk, etc. keep our components clean from API calls and make our codebase more readable that's why using redux-thunk over useEffect is the best practice. Only states that can affect the component should be kept in the component otherwise when the codebase be grow up it will be hard to maintain.

Upvotes: 7

Related Questions