S
S
Space Around2019-07-28 05:20:37
React
Space Around, 2019-07-28 05:20:37

What does component state mean in React?

I have a hard time understanding the word state in relation to a component, as well as to an application in React. When studying React, I personally understood in this way that there is a component in which there are encapsulated variables stored in the state object, that is, you can cram any variables that will be used, but have nothing to do with the state. For example, there is a person component, inside which there is a state object, you can write ill: false, mood: 5, etc. there, but when studying React, apparently, write finger: 20, hand: 2 in the same state, but these variables have nothing to do with describing the human condition.
If someone can clearly explain the meaning of the state in this contest, I would be grateful!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Khan Bifov, 2019-07-28
@viksnamax

If your person changes the number of fingers or hands and some parts of your application depend on this change , then the number of fingers and hands is stored in the state. If your person is permanently ill or sad, these variables (i.e. constants) have nothing to do in the state.
State is a set of data that can change at runtime that your application depends on. It doesn't matter if the data has a predefined number of states (ill: true/false -> 2, likes: ... -> infinity), it's important that changing this data affects how the application works (UI redrawing)
State management is the main reason the existence of such frameworks / libraries, so it's worth exploring the issue .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question