Skip to content

Commit f3f005d

Browse files
committed
document ImportedController
1 parent d200d5e commit f3f005d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const ClientSideOnly = () => (
144144
const ServerSideFriendly = () => (
145145
<LazyBoundary>
146146
{' '}
147-
// LazyBoundary is Suspense on the client, and "nothing" on the server
147+
// LazyBoundary is Suspense* on the client, and "nothing" on the server
148148
<Component />
149149
</LazyBoundary>
150150
);
@@ -254,7 +254,7 @@ If you have `imported` definition in one file, and use it from another - just `i
254254

255255
- `importFunction` - function which resolves with Component to be imported.
256256
- `options` - optional settings
257-
- `options.async` - activates react suspense support. Will throw a Promise in a Loading State - use it with Suspense in a same way you use **React.lazy**.
257+
- `options.async` - activates react suspense support. Will throw a Promise in a Loading State - use it with Suspense in a same way you use **React.lazy**. See [working with Suspense](working-with-suspense)
258258
- `options.LoadingComponent` - component to be shown in Loading state
259259
- `options.ErrorComponent` - component to be shown in Error state. Will re-throw error if ErrorComponent is not set. Use ErrorBoundary to catch it.
260260
- `options.onError` - function to consume the error, if one will thrown. Will rethrow a real error if not set.
@@ -291,6 +291,10 @@ Hints:
291291
- use `options.import=false` to perform conditional import - `importFunction` would not be used if this option set to `false.
292292
- use `options.track=true` to perform SSR only import - to usage would be tracked if this option set to `false.
293293

294+
##### ImportedController
295+
296+
- `<ImportedControoler>` - a controller for Suspense Hydration. **Compulsory** for async/lazy usecases
297+
294298
##### Misc
295299

296300
There is also API method, unique for imported-component, which could be useful on the client side
@@ -442,12 +446,17 @@ Before rendering your application you have to ensure - all parts are loaded.
442446
`rehydrateMarks` will load everything you need, and provide a promise to await.
443447

444448
```js
445-
import { rehydrateMarks } from 'react-imported-component';
449+
import { rehydrateMarks, ImportedController } from 'react-imported-component';
446450

447451
// this will trigger all marked imports, and await for competition.
448452
rehydrateMarks().then(() => {
449-
// better
450-
ReactDOM.hydrate(<App />, document.getElementById('main'));
453+
// better (note ImportedController usage)
454+
ReactDOM.hydrate(
455+
<ImportedController>
456+
<App />
457+
</ImportedController>,
458+
document.getElementById('main')
459+
);
451460
// or
452461
ReactDOM.render(<App />, document.getElementById('main'));
453462
});

yarn.lock

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15976,7 +15976,7 @@ ts-pnp@^1.1.6:
1597615976
resolved "https://registry.yarnpkg.com/ts-pnp/-/ts-pnp-1.2.0.tgz#a500ad084b0798f1c3071af391e65912c86bca92"
1597715977
integrity sha512-csd+vJOb/gkzvcCHgTGSChYpy5f1/XKNsmvBGO4JXS+z1v2HobugDz4s1IeFXM3wZB44uczs+eazB5Q/ccdhQw==
1597815978

15979-
tslib@^1.10.0, tslib@^1.6.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.3:
15979+
tslib@^1.6.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.3:
1598015980
version "1.10.0"
1598115981
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
1598215982
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==
@@ -15986,6 +15986,11 @@ tslib@^1.9.0:
1598615986
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
1598715987
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==
1598815988

15989+
tslib@^2.0.0:
15990+
version "2.1.0"
15991+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
15992+
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
15993+
1598915994
tslint-config-prettier@^1.18.0:
1599015995
version "1.18.0"
1599115996
resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz#75f140bde947d35d8f0d238e0ebf809d64592c37"

0 commit comments

Comments
 (0)