Skip to content

Instantly share code, notes, and snippets.

@danharper danharper/waitFor.js
Last active Feb 21, 2017

Embed
What would you like to do?
three ways to "waitFor" a prop to become non-null before rendering
// decorate the class, composition
function waitFor(prop) {
return ChildComponent => class extends Component {
render() {
return this.props[prop] ? <ChildComponent {...this.props} /> : null
}
}
}
// decorate the class, inheritance
function waitFor(prop) {
return ChildComponent => class extends ChildComponent {
render(...args) {
return this.props[prop] ? super.render(...args) : null
}
}
}
// decorate the render function directly
function waitFor(prop) {
return (target, key, descriptor) => {
return {
...descriptor,
value(...args) {
return this.props[prop] ? descriptor.value.apply(this, args) : null
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.