Accepted answer

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 Query

More Query from same tag