Answer the question
In order to leave comments, you need to log in
Why store the query result in the Store?
Good afternoon, I saw from good practices that, for example, a request to display products is made through Redux. Thus, storing values in the Store and using them if necessary. Please tell me, so that I can understand for myself why it is worth doing it through Redux and storing it in the Store rather than making a code request when required?
Answer the question
In order to leave comments, you need to log in
I didn't really understand. The request is made when required)
Let's imagine the case:
You have a list of products in one component, which you load with a request to the back, And in another component there is an inscription "1234 products found". They're on the same page, but far apart, so they're different components.
How do you make it so that based on the server's response, the data is displayed in two components?
React without redax: find/make some kind of parent component that will be "above" your two. Make a request in it, throw the result of the request into the necessary components through props. There is an obvious minus: it happens that there are 5-6 more components between the parent component and the desired component. We'll have to pass props through each one. It messes up the project. And if you suddenly need to throw the same data into some third component, you will have to redo
React + redux (or any other state manager, not necessarily redux):
In any component, call action, which makes a request and saves the result in store . If some component needs this data, it connects to the store, takes the necessary data from there, and that's it.
That is, a general recommendation: data should be stored in the store when it can be used by different components
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question