zahraei
zahraei

Reputation: 79

passing data between child and parent component in nested component react js

enter image description here

I used a component as a child as follows, and in the parent component, ie ShowBodyQuestionsForArchive component, I used the child component as follows: {children}

in ShowBodyQuestionsForArchive component(parent) i have another componet As follows:

enter image description here

I want to change the data of ShowImage component in ShowComparetiveItemsForArchive component(child), which is displayed as {children}

Upvotes: 0

Views: 529

Answers (1)

Shyam Kumar
Shyam Kumar

Reputation: 158

 const ShowComparativeQuestionForArchive = ({question, number, items}) => {
     changeShowImage(){
        //changedData
     }
       return(
          <ShowBodyQuestionForArchive question = {question} number = {number}> 
               <ShowComparativeItemsForArchive changeShowImage = {changeShowImage()} number = {number} items = {items} />
               {
                showImage ? <ShowImage {changedData} /> //example
               }
          <ShowBodyQuestionForArchive/>
       )
    }

Now call the prop (changeShowImage) in ShowComparativeItemsForArchive

Upvotes: 0

Related Questions