V
V
Vladimir T.2019-06-02 08:52:21
JavaScript
Vladimir T., 2019-06-02 08:52:21

What is the difference between global state and component state?

Keeping everything in the same global state is one of the best practices when using Redux in development. However, some authors write that storing everything up to the flags for managing modal windows and other UI elements that do not directly affect the business logic is an overhead. I want to understand the difference (pros, cons, pitfalls).
On the one hand, it seems convenient to encapsulate the state of a component within it for support and extension. If you need to change the behavior of a component, then the developer only needs to fix the code inside this component.
On the other hand, nothing prevents storing the state in a common store and describing how to work with it in actions and reducers along with other component code.
As a result, it seems that at the price of encapsulation, we turn the component into a black box. Perhaps I'm missing something?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2019-06-02
@vachuahe

Keeping everything in the same global state is one of the good practices when using Redux in development.

Who told you this?
It's true
Do you feel the difference between "it's convenient for support and expansion" and "nothing gets in the way"?
"Nothing hinders" you write as you like - but what good will it do?
Yes. and that's good

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question