Skip to content

Instantly share code, notes, and snippets.

@cecigarcia
Last active February 22, 2018 11:58
Show Gist options
  • Save cecigarcia/ecc00b942364e6e0da07525b3605d23a to your computer and use it in GitHub Desktop.
Save cecigarcia/ecc00b942364e6e0da07525b3605d23a to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class CustomComponent extends Component {
apiMethod() { /* ... */ }
}
class ParentComponent extends Component {
handleClick = () => this.component.apiMethod();
render() {
return (
<div>
<button onClick={this.handleClick}>call api method!</button>
<CustomComponent ref={r => this.component = r } />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment