This is an example repository of lazily loading React in webpack.
npm install && npm start
npm install && npm run build
It supports two APIs:
import React from 'react';
import { LazilyLoadFactory } from './LazilyLoad';
export default LazilyLoadFactory(class extends React.Component {
render() {
return (
<div
ref={(ref) => this.props.$(ref).css('background-color', 'red')}>
Hello
</div>
);
}
}, {
$: () => System.import('jquery'),
});
import LazilyLoad, {importLazy} from './LazilyLoad';
import React from 'react';
<LazilyLoad modules={{
LoadedLate: () => importLazy(System.import('./LoadedLate'))
}}>
{({LoadedLate}) => <LoadedLate />}
</LazilyLoad>