Answer the question
In order to leave comments, you need to log in
How to change the local state of a component using the parent method?
There are two components: parent => child (childs are displayed in the map)
There is a method for changing state in parent, I pass it to child.
There is a local child state, how to change it? (for one)
1. This method must be used in child to change the state - https://dropmefiles.com/kq47Y
2. https://dropmefiles.com/5ykDr
3. In the selected component, you need to change the state - https://dropmefiles .com/bEiTA
4. We change this state with the parent method - https://dropmefiles.com/VhKko
5. Here you need to call the parent method on click - https://dropmefiles.com/H4aY6
UPD: solved the problem, one instance of the object was created, further only links to it. Therefore, state changed in all elements of MAPA.
Answer the question
In order to leave comments, you need to log in
If you need to change the local state in child, use setState, if you need to get data in child from parent - pass it through props.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question