Last active
August 5, 2016 12:53
-
-
Save thekevinscott/3fea8a82d24d1c8994aaf6629c9c3e29 to your computer and use it in GitHub Desktop.
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
class WrapperComponent extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
handledMounted: false, | |
}; | |
this.refHandler = this.refHandler.bind(this); | |
this.componentWillAppear = this.componentWillAppear.bind(this); | |
} | |
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(); | |
if (!this.state.handleMounted) { | |
this.setState({ | |
handleMounted: false, | |
}); | |
this.componentWillAppear(); | |
} | |
} | |
} | |
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