You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library is an evolution of [`code-split-component`](https://github.com/ctrlplusb/code-split-component). Unlike `code-split-component` this library does not require that you use either Webpack or Babel. Instead it provides you a pure Javascript/React API which has been adapted in a manner to make it generically useful for lazy-loaded Components, with support for modern code splitting APIs (e.g `import()`, `System.import`, `require.ensure`).
43
+
This library does not require that you use either Webpack or Babel. Instead it provides you a generic and "pure" Javascript/React API which allows for the expression of lazy-loaded Components. It's `Promise`-based API naturally allows you to take advantage of modern code splitting APIs (e.g `import()`, `System.import`, `require.ensure`).
44
+
45
+
## Features
46
+
47
+
- Supports _any_ major code splitting API.
48
+
- Show a `LoadingComponent` until your component is resolved.
49
+
- Show an `ErrorComponent` if your component resolution fails.
50
+
- Prevents flash-of-content by tracking already resolved Components.
51
+
- Full server side rendering support, allowing client side state rehydration, and avoiding React checksum errors.
52
+
- Uses the generalised [`react-async-bootstrapper`](https://github.com/ctrlplusb/react-async-bootstrapper) allowing you to optimally integrate with other async pre-loader libraries, such as [`react-jobs`](https://github.com/ctrlplusb/react-jobs) for your async data loading needs.
41
53
42
54
## Demo
43
55
44
56
You can see a "live" version [here](https://react-universally.now.sh/). This is a deployment of the "next" branch of ["React, Universally"](https://github.com/ctrlplusb/react-universally). Open the network tab and then click the menu items to see the asynchronous component resolving in action.
45
57
46
58
## Examples
47
59
48
-
The below examples show off a full workflow of using the `createAsyncComponent` and `withAsyncComponents` helpers.
60
+
The examples below make use of the `System.import` API supported by Webpack v2 which provides us with code splitting on our asynchronous components.
49
61
50
-
In some of the examples below we are going to be making use of the `System.import` API supported by Webpack v2 which provides us with code splitting on our asynchronous components.
62
+
### Standard Usage
51
63
52
-
### Browser Only Application
64
+
This is how you would use `react-async-component` in a "standard" React application (i.e. browser side only).
53
65
54
-
This is how you would use `react-async-component` in a "browser only" React application.
55
-
56
-
Firsly you need to wrap the rendering of your application with our helper:
66
+
Firsly you need to wrap the rendering of your application with the `AsyncComponentProvider`:
Now, let's create an async `Product` component that will be used within your application. I recommend that you use the following folder/file for your components:
83
85
84
86
```
85
-
|- AsyncProduct
87
+
|- Product
86
88
|- index.js
87
-
|- Product.js
89
+
|- AsyncProduct.js
88
90
```
89
91
90
-
The `./AsyncProduct/Product.js` could have the following example contents:
0 commit comments