G
G
gorwhoami2020-05-07 14:58:30
React
gorwhoami, 2020-05-07 14:58:30

Where do you think it is better to make requests to the server in React? In the business logic or in the component?

I'm still new to React and development in general. Please give an example of when to do in the BL and when in the component (if at all)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Suntsev, 2020-05-07
@gorwhoami

Queries are best done in middleware.
You can write a function for automatically getting data yourself, or you can use either
redux-api-middleware
Or
redux-api-call
It is also quite possible, especially if you have a back-end distributed in different places, to use redux-thunk, or redux-saga
Here is an article . where there are connection examples
In components, it is better not to make requests, with rare exceptions, when the component is directly related to external data (for example, some kind of currency counter that requests data from the central bank)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question