Skip to content

Instantly share code, notes, and snippets.

@Develer
Created July 26, 2019 15:57
Show Gist options
  • Save Develer/4d5208fa37af299803b9f6339509cf90 to your computer and use it in GitHub Desktop.
Save Develer/4d5208fa37af299803b9f6339509cf90 to your computer and use it in GitHub Desktop.
React. Call neighbour method
import React, { Component } from 'react';
import { render } from 'react-dom';
class Parent extends Component {
constructor(props) {
super(props);
this.graphView = React.createRef();
}
render() {
return (
<div>
<GraphView ref={this.graphView} />
<GraphControl graphView={this.graphView} />
</div>
);
}
}
class GraphView extends Component {
getGraphViewAlert() {
console.log('Blah!');
}
render() {
return <h1>GraphView</h1>;
}
}
class GraphControl extends Component {
onClick = () => {
this.props.graphView.current.getGraphViewAlert();
};
render() {
return (
<div>
<h1>GraphControl</h1>
<button onClick={this.onClick}>Click</button>
</div>
)
}
}
render(<Parent />, document.getElementById('root'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment