score:0

You will have to firstly set the hierarchy of your components such as parent, sibling or child component. You can pass information from parent to child component through props.

Reverse flow occurs as a callback function. If you want to call a function from parent component, create a function inside it and pass function as props.

 class ReportModal extends React.Component {
   constructor(props) {
   super(props);
   this.state = {
     modal: false,
     imagesList: [],
     code: []
   };

  this.toggle = this.toggle.bind(this);
 }

toggle(modal) {
   this.setState({
    modal: modal
   });
  }

 render() {
     return(
      <component2 mod={this.toggle}/>
        )
      }

The child component will call this function on the occurrence of event and provide child data.

  class Component2 extends React.Component {
           constructor(props) {
           super(props);
          this.handleClick=this.handleClick.bind(this);
        }

    handleClick(){
       this.props.mod(true)
      }
       

   render(){
       return (
             <button onClick={this.handleClick}></button>
         )}
        }
     

   

Related Query

More Query from same tag