Guest User

Untitled

a guest
Mar 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. loader: () => import("../containers/HomeAContainer")
  2.  
  3. import React, { Component } from 'react';
  4.  
  5. const asyncComponent = ( importComponent ) => {
  6. return class extends Component{
  7. state = { component: null }
  8.  
  9. componentDidMount(){
  10. importComponent().then(cmp =>{
  11. this.setState({component: cmp.default});
  12. });
  13. }
  14.  
  15. render (){
  16. const C = this.state.component;
  17. return C ? <C {...this.props} /> : null;
  18. }
  19. }
  20. }
  21.  
  22. export default asyncComponent;
  23.  
  24. import Exemple from './example/example';
  25.  
  26. Import asyncComponent from './asyncComponent';
  27. const asyncExample = asyncComponent(()=>{
  28. return import('./example/example');
  29. });
Add Comment
Please, Sign In to add comment