2

I have using to react-graph-vis package like below

    <Graph
      ref={graph}
      graph={data}
      options={options()}
      events={events}
    />

event prop triggers when i press the graph element and events func like below

  const events = {
    select: function(event) {
      var { nodes, edges } = event;
    }
  };

I want to access the event from another button onClick, how can I do that, thanks for suggestion

Alisan26
  • 323
  • 2
  • 12

1 Answers1

1

Make events a global variable. Set it in the state as myEvent or whatever you'd like to name it and do this:

this.setState({myEvent: events}) // replace myEvent as whatever you'd like to call it

You can reference it by this.state.myEvent. To call select do this.state.myEvent.select(e) assuming e is the event parameter.

new Q Open Wid
  • 2,225
  • 2
  • 18
  • 34