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
I recommend that you use the following folder/file structure:
73
67
74
-
exportdefaultfunctionProduct({ productId }) {
75
-
return<div>You are viewing product {productId}</div>;
76
-
}
68
+
```
69
+
|- components
70
+
|- AsyncProduct
71
+
|- index.js // contains asyncComponent
72
+
|- Product.js // The component you want resolved asynchronously
77
73
```
78
74
79
-
Now, you can simply import `Product` anywhere in your application and use it exactly as you would any other component.
75
+
Now, you can simply import `AsyncProduct` anywhere in your application and use it exactly as you would any other component.
80
76
81
77
For example:
82
78
83
79
```jsx
84
-
importReactfrom'react';
85
-
importProductfrom'./components/Product';
86
-
87
-
constMyApp= () => (
88
-
<div>
89
-
<h1>Welcome to My App</h1>
90
-
// 👇 Use as "normal"
91
-
<Product productId={1337} />
92
-
</div>
93
-
);
94
-
95
-
exportdefaultMyApp;
80
+
importAsyncProductfrom'./components/AsyncProduct'
81
+
82
+
exportdefaultfunctionMyApp() {
83
+
return (
84
+
<div>
85
+
<h1>Welcome to My App</h1>
86
+
<AsyncProduct id={1337} />
87
+
</div>
88
+
)
89
+
}
96
90
```
97
91
98
-
🚀
99
-
100
-
You have a lot more power than is shown here. Be sure to check out the [`API`](#api) for more.
101
-
102
92
## API
103
93
104
94
### `asyncComponent(config)`
@@ -117,7 +107,7 @@ The asynchronous component factory. Config goes in, an asynchronous component co
117
107
-__`'render'`__ - Your asynchronous component will be resolved and rendered on the server. It's children will
118
108
be checked to see if there are any nested asynchronous component instances, which will then be processed based on the `serverMode` value that was associated with them.
119
109
-__`'defer'`__ - Your asynchronous component will _not_ be rendered on the server, instead deferring rendering to the client/browser.
120
-
-__`'boundary'`__ - Your asynchronous component will be resolved and rendered on the server. However, if it has a nested asynchronous component instance within it's children that component will be ignored and treated as being deferred for rendering in the client/browser instead.
110
+
-__`'boundary'`__ - Your asynchronous component will be resolved and rendered on the server. However, if it has a nested asynchronous component instance within it's children that component will be ignored and treated as being deferred for rendering in the client/browser instead (it's serverMode will be ignored).
121
111
We highly recommend that you consider using `defer` as much as you can.
##### Webpack `import` / `System.import` Code Splitting API
160
-
161
-
Note: `System.import` is considered deprecated and will be replaced with `import`, but for now they can be used interchangeably (you may need a Babel plugin for the `import` syntax).
@@ -177,7 +162,7 @@ Currently only useful when building server side rendering applications. Wraps yo
177
162
178
163
### `createAsyncContext()`
179
164
180
-
Creates an asynchronous context that can be used by the `<AsyncComponentProvider />`. The context is an object that exposes the following properties to you:
165
+
Creates an asynchronous context for use by the `<AsyncComponentProvider />`. The context is an object that exposes the following properties to you:
181
166
182
167
-`getState()` (_() => Object_) : A function that when executed gets the current state of the `<AsyncComponentProvider />`. i.e. which async components resolved / failed to resolve etc. This is especially useful for server sider rendering applications where you need to provide the server rendered state to the client instance in order to ensure the required asynchronous component instances are resolved prior to render.
0 commit comments