0

I have a quick question.

If I have my API with ky endpointa ready.

Whats is the best approach to handle the calls to api in react and redux. Is a best way create a class api to fetch the data or what is the right way.

Thanks in advance

2 Answers2

0

I like to do my API calls in my React Components, usually from the lifecycle method componentDidMount then dispatch my redux actions when the request resolves. That way my redux actions can be entirely synchronous and I don't have to bring in any middleware such as redux-thunk. That's just me though, it's perfectly good to use middleware in order to put your API calls in your redux actions as well.

Jackson Lenhart
  • 630
  • 3
  • 7
  • 19
0

I'd rather use a redux middleware like redux-saga or redux-thunk to handle the store behavior and also make writing tests a lot easier.

Hawkes
  • 457
  • 1
  • 4
  • 16