Created
July 26, 2019 15:57
-
-
Save Develer/4d5208fa37af299803b9f6339509cf90 to your computer and use it in GitHub Desktop.
React. Call neighbour method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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