import React , { useState , useEffect } from 'react' ; /**
 * 异步组件（异步加载一些小组件）
 *
 * 使用方法:
 *
 * <Bundle load={() => import('../../components/sidebar')}>
 *  {Sidebar => <Sidebar />}
 * </Bundle>
 */ export default class AsyncComponent extends React . Component { state = { mod : null } ; constructor ( props ) { super ( props ) ; this . load = this . load . bind ( this ) ; } componentDidMount ( ) { this . load ( ) ; } load ( ) { this . setState ( { mod : null } ) ; this . props . load ( ) . then ( ( mod ) => { this . setState ( { mod : mod . default ? mod . default : mod } ) ; } ) ; } render ( ) { return this . state . mod ? this . props . children ( this . state . mod ) : null ; } }