R
R
Roman Yakimchuk2019-12-01 03:22:36
JavaScript
Roman Yakimchuk, 2019-12-01 03:22:36

When to use Redux?

Friends, good morning,
I'm trying to figure out with Redux, in which cases to apply it. I clearly understand why it is needed, this is a great solution for exchanging state between any components in the application and for managing the state of the application.
The use cases are not entirely clear.
In theory, this is a solution for exchanging state between unrelated components, such as a list of products in the cart, which is needed both in the header, and on specific pages, and on the page of any product, and in the list of related purchases.
In fact, I see people using it as the main storage for views, even if it's not needed there at all. For example, there is a page with movie search results, or just a movie catalog page, and this data (which is important, dynamic, and it always needs to be reloaded when entering the page) is stored by many in the Redux store, and not in the local state of the component (page ).
So how do you determine when you need a global store and when you need a local store at the component or route level?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2019-12-01
@yakimchuk-ry

There should be one and only one source of truth in an application. State stores provided by libraries such as redux/mobx/vuex/... are very well suited for the role of such a source
.
In very simple terms, while a certain state of a module / component is purely local, that is, it does not affect anything outside of this component - it can (and often needs to) be stored locally, but it is imperative to absolutely observe the encapsulation of this state, because as soon as it "leaked" outside, it ceases to be local and becomes general, and there it is already close to several sources of truth.
The state store solves this problem, thus becoming the only source of truth that everyone can trust.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question