@alepha/react 0.11.6 → 0.11.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alepha/react",
3
3
  "description": "Build server-side rendered (SSR) or single-page React applications.",
4
- "version": "0.11.6",
4
+ "version": "0.11.9",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=22.0.0"
@@ -17,23 +17,23 @@
17
17
  "src"
18
18
  ],
19
19
  "dependencies": {
20
- "@alepha/core": "0.11.6",
21
- "@alepha/datetime": "0.11.6",
22
- "@alepha/logger": "0.11.6",
23
- "@alepha/router": "0.11.6",
24
- "@alepha/server": "0.11.6",
25
- "@alepha/server-cache": "0.11.6",
26
- "@alepha/server-links": "0.11.6",
27
- "@alepha/server-static": "0.11.6"
20
+ "@alepha/core": "0.11.9",
21
+ "@alepha/datetime": "0.11.9",
22
+ "@alepha/logger": "0.11.9",
23
+ "@alepha/router": "0.11.9",
24
+ "@alepha/server": "0.11.9",
25
+ "@alepha/server-cache": "0.11.9",
26
+ "@alepha/server-links": "0.11.9",
27
+ "@alepha/server-static": "0.11.9"
28
28
  },
29
29
  "devDependencies": {
30
- "@alepha/testing": "0.11.6",
31
- "@biomejs/biome": "^2.3.4",
32
- "@types/react": "^19.2.2",
33
- "@types/react-dom": "^19.2.2",
30
+ "@alepha/testing": "0.11.9",
31
+ "@biomejs/biome": "^2.3.5",
32
+ "@types/react": "^19.2.4",
33
+ "@types/react-dom": "^19.2.3",
34
34
  "react": "^19.2.0",
35
35
  "react-dom": "^19.2.0",
36
- "tsdown": "^0.16.1",
36
+ "tsdown": "^0.16.4",
37
37
  "typescript": "^5.9.3",
38
38
  "vitest": "^4.0.8"
39
39
  },
@@ -1,29 +1,37 @@
1
- import type { State } from "@alepha/core";
1
+ import type { State, Static, TAtomObject } from "@alepha/core";
2
+ import { Atom } from "@alepha/core";
2
3
  import { useEffect, useMemo, useState } from "react";
3
4
  import { useAlepha } from "./useAlepha.ts";
4
5
 
5
6
  /**
6
7
  * Hook to access and mutate the Alepha state.
7
8
  */
8
- export const useStore = <Key extends keyof State>(
9
- key: Key,
9
+ function useStore<T extends TAtomObject>(
10
+ target: Atom<T>,
11
+ defaultValue?: Static<T>,
12
+ ): UseStoreReturn<Static<T>>;
13
+ function useStore<Key extends keyof State>(
14
+ target: Key,
10
15
  defaultValue?: State[Key],
11
- ): [State[Key], (value: State[Key]) => void] => {
16
+ ): UseStoreReturn<State[Key]>;
17
+ function useStore(target: any, defaultValue?: any): any {
12
18
  const alepha = useAlepha();
13
19
 
14
20
  useMemo(() => {
15
- if (defaultValue != null && alepha.state.get(key) == null) {
16
- alepha.state.set(key, defaultValue);
21
+ if (defaultValue != null && alepha.state.get(target) == null) {
22
+ alepha.state.set(target, defaultValue);
17
23
  }
18
24
  }, [defaultValue]);
19
25
 
20
- const [state, setState] = useState(alepha.state.get(key));
26
+ const [state, setState] = useState(alepha.state.get(target));
21
27
 
22
28
  useEffect(() => {
23
29
  if (!alepha.isBrowser()) {
24
30
  return;
25
31
  }
26
32
 
33
+ const key = target instanceof Atom ? target.key : target;
34
+
27
35
  return alepha.events.on("state:mutate", (ev) => {
28
36
  if (ev.key === key) {
29
37
  setState(ev.value);
@@ -33,8 +41,12 @@ export const useStore = <Key extends keyof State>(
33
41
 
34
42
  return [
35
43
  state,
36
- (value: State[Key]) => {
37
- alepha.state.set(key, value);
44
+ (value: any) => {
45
+ alepha.state.set(target, value);
38
46
  },
39
47
  ] as const;
40
- };
48
+ }
49
+
50
+ export type UseStoreReturn<T> = [T, (value: T) => void];
51
+
52
+ export { useStore };
@@ -241,7 +241,7 @@ export class ReactServerProvider {
241
241
  return;
242
242
  }
243
243
 
244
- this.log.info("SSR (vite) OK");
244
+ this.log.info("SSR (dev) OK");
245
245
 
246
246
  const url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;
247
247