Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thekevinscott/19e323b86f915009de64e7002af7eddc to your computer and use it in GitHub Desktop.
Save thekevinscott/19e323b86f915009de64e7002af7eddc to your computer and use it in GitHub Desktop.
class WrapperComponent extends Component {
constructor(props) {
super(props);
this.state = {
handledMounted: false,
};
this.refHandler = this.refHandler.bind(this);
this.componentWillAppear = this.componentWillAppear.bind(this);
}
componentWillMount() {
this.componentWillAppear();
}
componentWillAppear() {
if (this.instance) {
if (!this.instance.componentWillAppear) {
console.warn('You called connectFocus with a component that failed to implement componentWillAppear', this.instance);
} else {
this.instance.componentWillAppear();
}
}
}
refHandler(c) {
if (!this.instance) {
this.instance = c.getWrappedInstance();
}
}
render() {
return (
<WrappedComponent
{...this.props}
ref={this.refHandler}
/>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment