Skip to content

Commit 7ce66b1

Browse files
committed
[FIX] various
1 parent f65a623 commit 7ce66b1

138 files changed

Lines changed: 378 additions & 329 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Go to [Demo](https://ndriadev.github.io/react-tools) to see and try all implemen
171171

172172
- [_ErrorBoundary_](#ErrorBoundary)
173173
- [_For_](#For)
174-
- [_Lazy_](#Lazy)
174+
- [_LazyComponent_](#LazyComponent)
175175
- [_Show_](#Show)
176176
- [_SwitchCase_](#SwitchCase)
177177

@@ -992,11 +992,11 @@ Component to optimize the rendering of a list of elements without need to specif
992992
For = memo(<T extends unknown>({ of, children, filter, map, sort, elementKey, fallback }: ForProps<T>)
993993
```
994994
995-
### Lazy
995+
### LazyComponent
996996
997-
Component Wrapper to lazy loading a Component. [See demo](https://ndriadev.github.io/react-tools/#/components/Lazy)
997+
Component Wrapper to lazy loading a Component. [See demo](https://ndriadev.github.io/react-tools/#/components/LazyComponent)
998998
```tsx
999-
Lazy<T extends { default: ComponentType<unknown> } | { [k: string]: ComponentType<unknown> }>({ factory, componentName, fallback, beforeLoad, afterLoad }: { factory: () => Promise<T>, componentName?: string, fallback?: ReactNode, beforeLoad?: ()=>void, afterLoad?: ()=>void })
999+
LazyComponent<T extends { default: ComponentType<unknown> } | { [k: string]: ComponentType<unknown> }>({ factory, componentName, fallback, beforeLoad, afterLoad }: { factory: () => Promise<T>, componentName?: string, fallback?: ReactNode, beforeLoad?: ()=>void, afterLoad?: ()=>void })
10001000
```
10011001
10021002
### Show

apps/react-tools-demo/src/layout/MainLayout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,15 +1275,15 @@ export default function MainLayout() {
12751275
For
12761276
</Link>
12771277
<Link
1278-
className={pathname === "/components/Lazy" ? 'active' : ''}
1279-
ref={node => linksRef.current["Lazy"] = node}
1280-
to="/components/Lazy"
1278+
className={pathname === "/components/LazyComponent" ? 'active' : ''}
1279+
ref={node => linksRef.current["LazyComponent"] = node}
1280+
to="/components/LazyComponent"
12811281
onClick={() => {
12821282
containerRef.current?.scrollTo(0, 0);
12831283
window.innerWidth < 1190 && closeNav();
12841284
}}
12851285
>
1286-
Lazy
1286+
LazyComponent
12871287
</Link>
12881288
<Link
12891289
className={pathname === "/components/Show" ? 'active' : ''}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# LazyComponent
2+
Component Wrapper to lazy loading a Component. [See demo](https://ndriadev.github.io/react-tools/#/components/LazyComponent)
3+
4+
## Usage
5+
6+
```tsx
7+
export default function LC() {
8+
return (
9+
<LazyComponent
10+
factory={() => import('./LazyComp').then(async res => {
11+
await new Promise(resolve => setTimeout(resolve, 5000));
12+
return res;
13+
})}
14+
fallback={<p>Loading component...</p>}
15+
/>
16+
);
17+
}
18+
```
19+
20+
> The component uses _LazyComponent_ component to lazy load a component imported dynamically by _factory_ prop. The component loading is delayed by 5 seconds. During this time, _fallback_ prop is shown that renders a p element with the text __Loading component...__.
21+
22+
23+
## API
24+
25+
```tsx
26+
LazyComponent<T extends { default: ComponentType<unknown> } | { [k: string]: ComponentType<unknown> }>({ factory, componentName, fallback, beforeLoad, afterLoad }: { factory: () => Promise<T>, componentName?: string, fallback?: ReactNode, beforeLoad?: ()=>void, afterLoad?: ()=>void })
27+
```
28+
29+
> ### Params
30+
>
31+
> - __param__: _Object_
32+
properties to load component.
33+
> - __param.factory__: _() => Promise<{ [k:string]: T }>_
34+
function that returns a Promise or another thenable.
35+
> - __param.componentName?__: _string_
36+
name of the of the module to load lazy. If it is missing, and the _load_ execution result not have a default property, the first key in res is returned as result.
37+
> - __object.fallback?__: _ReactNode_
38+
optional element to render when _when_ prop is false.
39+
> - __param.beforeLoad?__: _()=>void_
40+
function that will be executed before loading component .
41+
> - __param.afterLoad?__: _()=>void_
42+
function that will be executed after loading component .
43+
>
44+
45+
> ### Returns
46+
>
47+
> __element__
48+
> - _JSX.Element_
49+
>

apps/react-tools-demo/src/pages/components/lazy/Lazy.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/react-tools-demo/src/pages/components/lazy/LazyComponent.tsx renamed to apps/react-tools-demo/src/pages/components/lazyComponent/LazyComp.tsx

File renamed without changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { LazyComponent } from "../../../../../../packages/react-tools-lib/src";
2+
3+
/**
4+
The component uses _LazyComponent_ component to lazy load a component imported dynamically by _factory_ prop. The component loading is delayed by 5 seconds. During this time, _fallback_ prop is shown that renders a p element with the text __Loading component...__.
5+
*/
6+
export default function LC() {
7+
return (
8+
<LazyComponent
9+
factory={() => import('./LazyComp').then(async res => {
10+
await new Promise(resolve => setTimeout(resolve, 5000));
11+
return res;
12+
})}
13+
fallback={<p>Loading component...</p>}
14+
/>
15+
);
16+
}

apps/react-tools-demo/src/router/Router.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ComponentLayout from '../layout/ComponentLayout';
55
import { Spinner } from '../layout/Spinner';
66
import ErrorBoundaryMD from "../markdown/ErrorBoundary.md?raw"
77
import ForMD from "../markdown/For.md?raw"
8-
import LazyMD from "../markdown/Lazy.md?raw"
8+
import LazyComponentMD from "../markdown/LazyComponent.md?raw"
99
import ShowMD from "../markdown/Show.md?raw"
1010
import SwitchCaseMD from "../markdown/SwitchCase.md?raw"
1111
import alphanumericCompareMD from "../markdown/alphanumericCompare.md?raw"
@@ -137,7 +137,7 @@ import useWebWorkerMD from "../markdown/useWebWorker.md?raw"
137137
import useWebWorkerFnMD from "../markdown/useWebWorkerFn.md?raw"
138138
const ErrorBoundary = lazy((() => import('../pages/components/errorBoundary/ErrorBoundary').then(module => ({default: "default" in module ? module["default"] : module["ErrorBoundary"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
139139
const For = lazy((() => import('../pages/components/for/For').then(module => ({default: "default" in module ? module["default"] : module["For"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
140-
const Lazy = lazy((() => import('../pages/components/lazy/Lazy').then(module => ({default: "default" in module ? module["default"] : module["Lazy"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
140+
const LazyComponent = lazy((() => import('../pages/components/lazyComponent/LazyComponent').then(module => ({default: "default" in module ? module["default"] : module["LazyComponent"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
141141
const Show = lazy((() => import('../pages/components/show/Show').then(module => ({default: "default" in module ? module["default"] : module["Show"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
142142
const SwitchCase = lazy((() => import('../pages/components/switchCase/SwitchCase').then(module => ({default: "default" in module ? module["default"] : module["SwitchCase"]}))) as unknown as () => Promise<{ default: ComponentType; }>)
143143
import HomeWrapper from '../pages/home/HomeWrapper'
@@ -999,9 +999,9 @@ function Router() {
999999
</Suspense>
10001000
},
10011001
{
1002-
path: "Lazy",
1002+
path: "LazyComponent",
10031003
element: <Suspense fallback={<Spinner/>}>
1004-
<ComponentLayout markdown={LazyMD} component={<Lazy/>}/>
1004+
<ComponentLayout markdown={LazyComponentMD} component={<LazyComponent/>}/>
10051005
</Suspense>
10061006
},
10071007
{
@@ -1115,7 +1115,7 @@ function Router() {
11151115
{
11161116
path: "lazy",
11171117
element: <Suspense fallback={<Spinner/>}>
1118-
<ComponentLayout markdown={lazyMD} component={<Lazy/>}/>
1118+
<ComponentLayout markdown={lazyMD} />
11191119
</Suspense>
11201120
},
11211121
{

apps/react-tools-demo/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import mkcert from 'vite-plugin-mkcert'
44

55
// https://vitejs.dev/config/
66
export default defineConfig({
7-
base:"react-tools",
7+
base:"/react-tools",
88
server: {
99
host: true,
1010
https: true
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)