Skip to content

Instantly share code, notes, and snippets.

@Weiyuan-Lane
Created February 4, 2019 07:07
Show Gist options
  • Save Weiyuan-Lane/7236bb094a1fd72ede4f40a85a55c221 to your computer and use it in GitHub Desktop.
Save Weiyuan-Lane/7236bb094a1fd72ede4f40a85a55c221 to your computer and use it in GitHub Desktop.
Code splitting illustrating using component splitting library, React Loadable
import React from 'react'
import Loadable from 'react-loadable'
import LoadingComponent from 'scripts/components/LoadingComponent'
class ExamplePage extends React.Component {
static Component = Loadable({
loader: () => import(/* webpackChunkName: "ExamplePage" */ 'example'),
loading: LoadingComponent, // Lightweight LoadingComponent to use whenever this component is first loaded
modules: ['ExamplePage'] // Modules to load should be accessible from loader property above
})
render() {
return <ExamplePage.Component {...this.props} />
}
}
export default ExamplePage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment