await-component
Code-splitting with import() and loading boundaries
Features
- Supports any Promise based code-splitting API
import()
,require.ensure()
, etc - Display a custom loading component while waiting for sub-components to load.
- Handle timeouts and errors with a custom error component.
- Adds delay to prevent Flash of Loading Content
- Preload components with
preload
Install
yarn add await-component
;
Examples
Async(() => <Promise>)
Using ;; const Container = ;const Sum = ; <Await loading=<div>Loading...</div> error=<div>ERROR!</div>> <Container> <Sum a=1 b=2 /> <Sum a=2 b=2 /> <Sum a=5 b=5 /> </Container> </Await>;
Preloading
;; const Container = ;const Sum = ; ; <Await loading=<div>Loading...</div> error=<div>ERROR!</div>> <Container> <Sum a=1 b=2 /> <Sum a=2 b=2 /> <Sum a=5 b=5 /> </Container> </Await>;
Using JSX Pragma (experimental)
/* @jsx Async.createElement */;; const Container = import'./Container';const Sum = import'./Sum'; <Await loading=<div>Loading...</div> error=<div>ERROR!</div>> <Container> <Sum a=1 b=2 /> <Sum a=2 b=2 /> <Sum a=5 b=5 /> </Container> </Await>;
Changelog
See the Changelog
Contributing
See the Contributors Guide