1

I have a file called map.js which has the map and markers

{Towers.TowerList.map((tower) => (
<Marker key={tower.id}
        position={tower.coords}

        onClick={() => {
          Drawgraph(tower); //Doubtful
          setTower(tower)
        }
        } />

The setTower() comes from a React hook.

I want to plot a chartjs graph when a particular marker is clicked. But chart is to be made in D.js, while the information for clicked graph is in this one. I wanted so that Drawgraph() could determeine which dataset to use, make a chart and take the chart to D.js (where chart is to be displayed). This is what D.js looks like :

//somewhere in D.js
<div className="chart-wrapper">
       <DrawGraph /> //Doubtful
</div>

How to go about this situation?

2
  • 2
    Same as data you can pass functions also as props. Commented Dec 22, 2019 at 6:53
  • 1
    @DananjayaAriyasena will it be possible to share a code snippet for doing the same in this case? I did try but failed ;_; Commented Dec 22, 2019 at 7:12

1 Answer 1

1

In react you can use props to pass data from one component to its child component. If the <DrawGraph /> Is not a child component, you can use state management libraries like redux or the built-in Context API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.