@alepha/react 0.9.3 → 0.9.5
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 +64 -6
- package/dist/index.browser.js +442 -328
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +644 -482
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +402 -339
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +412 -349
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +641 -484
- package/dist/index.js.map +1 -1
- package/package.json +16 -11
- package/src/components/Link.tsx +2 -5
- package/src/components/NestedView.tsx +164 -19
- package/src/components/NotFound.tsx +1 -1
- package/src/descriptors/$page.ts +100 -5
- package/src/errors/Redirection.ts +8 -5
- package/src/hooks/useActive.ts +25 -35
- package/src/hooks/useAlepha.ts +16 -2
- package/src/hooks/useClient.ts +7 -4
- package/src/hooks/useInject.ts +4 -1
- package/src/hooks/useQueryParams.ts +9 -6
- package/src/hooks/useRouter.ts +18 -31
- package/src/hooks/useRouterEvents.ts +30 -22
- package/src/hooks/useRouterState.ts +8 -20
- package/src/hooks/useSchema.ts +10 -15
- package/src/hooks/useStore.ts +0 -7
- package/src/index.browser.ts +14 -11
- package/src/index.shared.ts +2 -3
- package/src/index.ts +27 -31
- package/src/providers/ReactBrowserProvider.ts +151 -62
- package/src/providers/ReactBrowserRendererProvider.ts +22 -0
- package/src/providers/ReactBrowserRouterProvider.ts +137 -0
- package/src/providers/{PageDescriptorProvider.ts → ReactPageProvider.ts} +121 -104
- package/src/providers/ReactServerProvider.ts +90 -76
- package/src/{hooks/RouterHookApi.ts → services/ReactRouter.ts} +49 -62
- package/src/contexts/RouterContext.ts +0 -14
- package/src/providers/BrowserRouterProvider.ts +0 -155
- package/src/providers/ReactBrowserRenderer.ts +0 -93
package/README.md
CHANGED
|
@@ -10,12 +10,6 @@ This package is part of the Alepha framework and can be installed via the all-in
|
|
|
10
10
|
npm install alepha
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Alternatively, you can install it individually:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @alepha/core @alepha/react
|
|
17
|
-
```
|
|
18
|
-
|
|
19
13
|
## Module
|
|
20
14
|
|
|
21
15
|
Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.
|
|
@@ -24,16 +18,80 @@ The React module enables building modern React applications using the `$page` de
|
|
|
24
18
|
It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full
|
|
25
19
|
type safety and schema validation for route parameters and data.
|
|
26
20
|
|
|
21
|
+
This module can be imported and used as follows:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Alepha, run } from "alepha";
|
|
25
|
+
import { AlephaReact } from "alepha/react";
|
|
26
|
+
|
|
27
|
+
const alepha = Alepha.create()
|
|
28
|
+
.with(AlephaReact);
|
|
29
|
+
|
|
30
|
+
run(alepha);
|
|
31
|
+
```
|
|
32
|
+
|
|
27
33
|
## API Reference
|
|
28
34
|
|
|
29
35
|
### Descriptors
|
|
30
36
|
|
|
37
|
+
Descriptors are functions that define and configure various aspects of your application. They follow the convention of starting with `$` and return configured descriptor instances.
|
|
38
|
+
|
|
39
|
+
For more details, see the [Descriptors documentation](https://feunard.github.io/alepha/docs/descriptors).
|
|
40
|
+
|
|
31
41
|
#### $page()
|
|
32
42
|
|
|
33
43
|
Main descriptor for defining a React route in the application.
|
|
34
44
|
|
|
35
45
|
### Hooks
|
|
36
46
|
|
|
47
|
+
Hooks provide a way to tap into various lifecycle events and extend functionality. They follow the convention of starting with `use` and return configured hook instances.
|
|
48
|
+
|
|
49
|
+
#### useAlepha()
|
|
50
|
+
|
|
51
|
+
Main Alepha hook.
|
|
52
|
+
|
|
53
|
+
It provides access to the Alepha instance within a React component.
|
|
54
|
+
|
|
55
|
+
With Alepha, you can access the core functionalities of the framework:
|
|
56
|
+
|
|
57
|
+
- alepha.state() for state management
|
|
58
|
+
- alepha.inject() for dependency injection
|
|
59
|
+
- alepha.emit() for event handling
|
|
60
|
+
etc...
|
|
61
|
+
|
|
62
|
+
#### useClient()
|
|
63
|
+
|
|
64
|
+
Hook to get a virtual client for the specified scope.
|
|
65
|
+
|
|
66
|
+
It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
|
|
67
|
+
|
|
68
|
+
#### useInject()
|
|
69
|
+
|
|
70
|
+
Hook to inject a service instance.
|
|
71
|
+
It's a wrapper of `useAlepha().inject(service)` with a memoization.
|
|
72
|
+
|
|
73
|
+
#### useQueryParams()
|
|
74
|
+
|
|
75
|
+
Not well tested. Use with caution.
|
|
76
|
+
|
|
77
|
+
#### useRouter()
|
|
78
|
+
|
|
79
|
+
Use this hook to access the React Router instance.
|
|
80
|
+
|
|
81
|
+
You can add a type parameter to specify the type of your application.
|
|
82
|
+
This will allow you to use the router in a typesafe way.
|
|
83
|
+
|
|
84
|
+
class App {
|
|
85
|
+
home = $page();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const router = useRouter<App>();
|
|
89
|
+
router.go("home"); // typesafe
|
|
90
|
+
|
|
91
|
+
#### useRouterEvents()
|
|
92
|
+
|
|
93
|
+
Subscribe to various router events.
|
|
94
|
+
|
|
37
95
|
#### useStore()
|
|
38
96
|
|
|
39
97
|
Hook to access and mutate the Alepha state.
|