autosuspense 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -2
- package/package.json +1 -1
- package/autosuspense-lib-1.0.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
# AutoSupense
|
|
2
|
-
AutoSuspense is a
|
|
2
|
+
AutoSuspense is a small React utility that automatically builds and composes
|
|
3
|
+
Suspense fallback UI based on your component tree without manually wiring
|
|
4
|
+
nested fallback components.
|
|
3
5
|
|
|
4
6
|
## How to use?:
|
|
5
7
|
1. Install this library
|
|
6
|
-
```npm i autosuspense```
|
|
8
|
+
```npm i autosuspense```
|
|
9
|
+
|
|
10
|
+
2. Use it by calling and passing your components normally like ```<Supense>```:
|
|
11
|
+
```
|
|
12
|
+
import { AutoSuspense } from "autosuspense";
|
|
13
|
+
|
|
14
|
+
function App() {
|
|
15
|
+
return (
|
|
16
|
+
<AutoSuspense>
|
|
17
|
+
<Page />
|
|
18
|
+
</AutoSuspense>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. Inside each AutoSuspense component provide a fallback componet for that particular component via ```useSuspenseFallback``` hook.
|
|
24
|
+
```
|
|
25
|
+
import { useSuspenseFallback } from "autosuspense";
|
|
26
|
+
|
|
27
|
+
function UserCard() {
|
|
28
|
+
useSuspenseFallback(<div>Loading user…</div>);
|
|
29
|
+
|
|
30
|
+
// Component may suspend somewhere below
|
|
31
|
+
return <Profile />;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Important Caveats:
|
|
36
|
+
1. This library works on top of existing Suspense blocks and prebuilds your Fallback UI via render tree traversal.
|
|
37
|
+
2. This means that it uses Depth First searching to prebuild so react is only able to show prebuilt Ui when it first encounters a place to suspend. This could mean that rest of your fallback UI in next adjacent components never render.
|
|
38
|
+
|
|
39
|
+
### TBD:
|
|
40
|
+
1. Adding Default Skeletons.
|
|
41
|
+
2. Supporting existing Library skeleton implementations.
|
|
42
|
+
3. Adding a central config & template extension components & file to easily extend and manage your Fallback UI.
|
package/package.json
CHANGED
|
Binary file
|