Search code examples
javascriptreactjsreact-graph-vis

Accessing event trigger button onclick function


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


Solution

  • 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.