Created
March 2, 2017 06:12
-
-
Save ryanflorence/6a2fd32961f885968a63cf15fccf3e66 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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