How to from one component set state another component in react native?

Viewed 2839

I have a problem. I want to set state another component from one component but I don't know how to do it?

1 Answers

Component1: The component that you want to change the state from that.
Component2: The component that you want to change its state from another component.

  • If the the Component2 is child of the Component1, you can do this by passing new state as props to Component2.
  • If the Component2 is the parent of Component1, you should do this by a function that is defined in the Component2 (this function change the state of Component2) and passed to Component1 as a prop.
  • Otherwise you can use redux to manage the state and define a mapStateToProps function in Component2 to affect it by changing the state by Component1.
Related