Last active
April 11, 2017 20:26
-
-
Save danielepiccone/2cf8edc2b685137c0e064137383a093a 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
import React from 'react'; | |
import { getDataFromTree } from 'react-apollo/lib/index'; | |
class AsyncRoute extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
route: props.children | |
}; | |
} | |
componentWillReceiveProps(nextProps) { | |
const currentAppRoute = nextProps.children; | |
getDataFromTree(currentAppRoute) | |
.then(() => { | |
this.setState({ | |
route: currentAppRoute | |
}); | |
}) | |
.catch(err => { | |
console.error('Error getting data from tree: ', err); | |
throw err; | |
}); | |
} | |
render() { | |
return this.state.route; | |
} | |
} | |
AsyncRoute.propTypes = { | |
children: React.PropTypes.node.isRequired | |
}; | |
export default AsyncRoute; | |
~ |
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
import React from 'react'; | |
render( | |
<Router | |
routes={routes} | |
history={history} | |
render={props => ( | |
<AsyncRoute> | |
<RouterContext {...props} /> | |
</AsyncRoute> | |
)} | |
/>, reactRoot); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment