bhav_yea
bhav_yea

Reputation: 63

How to call a function in another component with props using ReactJS?

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?

Upvotes: 1

Views: 107

Answers (1)

B45i
B45i

Reputation: 2602

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.

Upvotes: 1

Related Questions