Answer the question
In order to leave comments, you need to log in
Is it possible to directly add value to state from redux?
The state flies when switching between tabs, it is not possible to fasten componentDidMount, since shouldComponentUpdate interferes. I registered a value from the redax in state, but is it possible to manipulate the state in this way?
state = {
data: this.props.counters[COUNTER_TYPE_ELECTRICITY] || null,
isLoading: false,
inProgress: false,
error: null,
activeItemIndex: 0
]
Answer the question
In order to leave comments, you need to log in
If the value is already in the props from the store, why write it to the state?
Your code looks like some kind of nonsense. If you set the state in the constructor, then write this.state = if
the
component is functional, then useState and setting the state from the prop is meaningless
This method exists for rare use cases where the state depends on changes in props over time. For example, it might be handy for implementing a component that compares its previous and next children to decide which of them to animate in and out.
The solution to your problem lies elsewhere.
Try to solve your task in the following way:
Initialize the component with the state from store(redux).
Next, change the state locally inside the component by doing setState and calling action in parallel to write the change to the store.
To be honest, without context, it is not clear what you are doing :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question