Home > Software design >  Pass data from on component to another react
Pass data from on component to another react

Time:06-08

I have a questionnaire and send an request to get all data back from the database, that match the answers. I then want to use the data in another component to display the results.

 <div className='row justify-content-end mt-3 pb-5'>
   <div className='btn btn-primary btn-block rounded shadow-sm result' onClick=this.getSelectedOptions}>Ergebnisanalyse</div>
</div>

My onClick triggers the function in a class component called "ImpactAnalysis" where i get my results back as an array of objects. Then i want to display the result in a class component "ResultPage"

CodePudding user response:

You can pass like this:

<ResultPage data={impactAnalysisResults} />

Then you will have this array on your ResultPage component.

const ResultPage = ({data}) => {
    const { impactAnalysisResults } = data;
}

CodePudding user response:

Simply send those data in a component as props. to send props to a component add key name and pair value with it. As example

<ResultPage data={impactAnalysisResults} />

from ResultPage catch values like

function ResultPage ({data}) {
    console.log(data) //check data object sent from parent component
    return (
    //show your data from 'data' props
    <div>{data}</div>
   )
}
  • Related