plotly / react-cytoscapejs

React component for Cytoscape.js network visualisations
MIT License
483 stars 68 forks source link

"Uncaught ReferenceError: cy is not defined" #27

Closed scottc11 closed 5 years ago

scottc11 commented 5 years ago

I cannot access the underlying Cytoscape instance via Reacts ref API. I get the following error in the console -> Uncaught ReferenceError: cy is not defined

class Container extends React.Component {
  constructor(props) {
    super(props);
    this.cy;
  }

  componentDidUpdate() {
    console.log(this.cy);
  }

  render() {
    return <CytoscapeComponent cy={ (cy) = this.cy = cy } elements={mockData} style={ { width: '600px', height: '600px' } } />;
  }
}

ReactDOM.render(<Container />, document.querySelector('#container'));

Upon inspecting the component.js file, I don't see any of the suggested syntax found in the React Docs. Am I doing something wrong?

Remimstr commented 5 years ago

The error is because of the way you're using the cy prop. It expects a function, so you should do: cy = { cy => this.cy = cy }

instead of: cy = { cy = this.cy = cy }

scottc11 commented 5 years ago

:man-facepalming:

daphnie-el commented 4 years ago

Did you find a solution to this problem. I am currently facing it and its preventing me from making a PR