Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Last active June 16, 2022 17:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeBelt/1fb48d4d52191c832692318c54626de1 to your computer and use it in GitHub Desktop.
Save codeBelt/1fb48d4d52191c832692318c54626de1 to your computer and use it in GitHub Desktop.
React Loadable TypeScript Examples
import * as Loadable from 'react-loadable';
import OptionsWithoutRender = LoadableExport.OptionsWithoutRender;
import AsyncLoader from '../components/AsyncLoader';
import {IProps} from './AddBeer';
const loadableOptions: OptionsWithoutRender<IProps> = {
loader: () => import(/* webpackChunkName: "AddBeer" */ './AddBeer'),
loading: AsyncLoader,
};
export default Loadable(loadableOptions);
import * as React from 'react';
import * as Loadable from 'react-loadable';
import OptionsWithRender = LoadableExport.OptionsWithRender;
import AsyncLoader from '../components/AsyncLoader';
import {IProps} from './AddBeer';
const loadableOptions: OptionsWithRender<IProps, any> = {
loader: () => import(/* webpackChunkName: "AddBeer" */ './AddBeer'),
loading: AsyncLoader,
render(loaded: any, props: IProps) {
const Component: any = loaded.default; // tslint:disable-line:variable-name
return <Component {...props} />;
},
};
export default Loadable(loadableOptions);
/*
<AddBeerAsync
data={'stuff'}
/>
*/
@codeBelt
Copy link
Author

@katesroad it's been awhile since I wrote this code but looks like LoadableExport is part of the react-loadable library.
https://cdn.jsdelivr.net/npm/@types/react-loadable@5.3.3/index.d.ts

Check out the latest way to code split with the use of React lazy
https://github.com/codeBelt/react-redux-architecture/blob/TypeScript/src/views/App.tsx#L12

Also check out my article on the latest way I build react apps
https://medium.com/@robertsavian/my-awesome-react-redux-structure-6044e5007e22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment