Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created March 2, 2017 06:12
Show Gist options
  • Save ryanflorence/6a2fd32961f885968a63cf15fccf3e66 to your computer and use it in GitHub Desktop.
Save ryanflorence/6a2fd32961f885968a63cf15fccf3e66 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
class Bundle extends Component {
state = {
mod: null
}
componentWillMount() {
this.load(this.props)
}
componentWillReceiveProps(nextProps) {
if (nextProps.load !== this.props.load) {
this.load(nextProps)
}
}
load(props) {
this.setState({
mod: null
})
props.load((mod) => {
this.setState({ mod: mod.default ? mod.default : mod })
})
}
render() {
return this.props.children(this.state.mod)
}
}
export default Bundle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment