Chartjs-How to pass function variable from one file to another in react

1👍

Just pass your score and question count as a prop to your LineChart component.

{showScore ? (
                <div className='score-section'>
                    You scored {score} out of {questions.length}

                    <LineChart
                        score={score}
                        question_count={questions.length}
                    />
                    
                </div>
            ) :

Then in your LineChart component, you can access them as

this.props.score
this.props.question_count

0👍

Yannick is right. i have to pass it as a prop.
i made a mistake, in app.js LineChart function I passed it like Linechart(score), it should be Line chart({score}).
corrected code is.

//App.js

<LineChart
                        score={score}
            total={questions.length}
                        />
//Chart.js
export default function LineChart({score,total})
and you can use score and total anywhere in you're function body.

Leave a comment