react-stateshape 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/README.md +10 -7
  2. package/package.json +49 -49
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # react-stateshape
2
2
 
3
- Shared state management and routing in React apps. Under the hood, routing is shared state management, too, with the shared data being the URL.
3
+ A shared state management and routing lib for React apps. Under the hood, routing is shared state management, too, with the shared data being the URL.
4
4
 
5
5
  Contents: [useExternalState](#useexternalstate) · [useRoute](#useroute) · [useNavigationStart / useNavigationComplete](#usenavigationstart--usenavigationcomplete) · [useRouteState](#useroutestate) · [Type-safe routes](#type-safe-routes) · [useTransientState](#usetransientstate) · [Annotated examples](#annotated-examples) · [Internals](#internals)
6
6
 
@@ -66,16 +66,19 @@ let App = () => (
66
66
 
67
67
  ### Filtering state updates
68
68
 
69
- ⬥ Use the optional `false` parameter in `useExternalState(state, false)`, as in `<ResetButton>` above, to tell the hook not to subscribe the component to tracking the external state updates. The common use case for it is when a component makes use of the external state value setter without using the state value itself.
69
+ ⬥ Use the optional `false` parameter in `useExternalState(state, false)`, as in `ResetButton` above, to tell the hook not to subscribe the component to tracking the external state updates. The common use case for it is when a component makes use of the external state value setter without using the state value itself.
70
70
 
71
71
  ⬥ Apart from setting the optional second parameter of `useExternalState(state, callback)` to a boolean value, use it as a render callback for more fine-grained control over component's re-renders in response to state changes:
72
72
 
73
73
  ```js
74
+ let itemState = new State({/* A map of `<id>: <item>` */});
75
+
76
+ // Renders a specific item from `itemState`
74
77
  let ItemCard = ({ id }) => {
75
78
  let [items, setItems] = useExternalState(itemState, (render, { current, previous }) => {
76
- // Assuming that the items have a `revision` property, re-render
77
- // `ItemCard` only if the relevant item's `revision` has changed.
78
- if (current[id].revision !== previous[id].revision) render();
79
+ // Assuming that the items have a `timestamp` property, re-render
80
+ // `ItemCard` only if the relevant item's `timestamp` has increased
81
+ if (current[id].timestamp > previous[id].timestamp) render();
79
82
  });
80
83
 
81
84
  // ...
@@ -102,7 +105,7 @@ let counterState = new PersistentState(0, { key: "counter" });
102
105
 
103
106
  ⬥ Set up interaction with a custom storage by setting `{ read(), write(value)? }` as `options` in `new PersistentState(value, options)`.
104
107
 
105
- ⬥ `PersistentState` skips interaction with the browser storage in non-browser environments, which makes it usable with SSR.
108
+ ⬥ `PersistentState` skips interaction with the browser storage in non-browser environments, which makes it usable with SSR. One way to avoid mismatch errors while hydrating SSR content based on a persisent state restored in the browser is using client-side rendering detection utilities such as [`react-clientside`](https://www.npmjs.com/package/react-clientside).
106
109
 
107
110
  ## useRoute
108
111
 
@@ -130,7 +133,7 @@ let App = () => {
130
133
 
131
134
  ⬥ `params` in dynamic values (as in `({ params }) => <Section id={params.id}/>` above) contains the URL pattern's capturing groups.
132
135
 
133
- ⬥ By default, `useRoute` and the other routing hooks described here make use of the browser's URL, if it's available. Otherwise, use `<RouteProvider href="/x">` to set a specific URL value. Common use cases: SSR and tests. A less common use case: custom routing behavior, including custom non-URL-based routing ([example](https://codesandbox.io/p/sandbox/tykt44?file=%252Fsrc%252FApp.tsx)).
136
+ ⬥ By default, `useRoute` makes use of the browser's URL, if it's available. Otherwise, use `<RouteProvider href={url}>` to set a specific URL value. Common use cases: SSR and tests. A less common use case: custom routing behavior, including custom non-URL-based routing ([example](https://codesandbox.io/p/sandbox/tykt44?file=%252Fsrc%252FApp.tsx)).
134
137
 
135
138
  ⬥ See also the [Type-safe routes](#type-safe-routes) section.
136
139
 
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "react-stateshape",
3
- "version": "0.2.1",
4
- "description": "Concise shared state management and routing in React apps",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
8
- "type": "module",
9
- "scripts": {
10
- "demo": "npx auxsrv tests/Shared_state_without_Context",
11
- "preversion": "npx npm-run-all shape test",
12
- "shape": "npx codeshape",
13
- "t3": "npx auxsrv tests/Tic-tac-toe",
14
- "test": "npx playwright test --project=chromium",
15
- "typecheck": "npx codeshape typecheck"
16
- },
17
- "repository": {
18
- "type": "git",
19
- "url": "git+https://github.com/axtk/react-stateshape.git"
20
- },
21
- "keywords": [
22
- "state",
23
- "state management",
24
- "react state management",
25
- "shared state",
26
- "global state",
27
- "routing",
28
- "react router"
29
- ],
30
- "license": "MIT",
31
- "author": "axtk",
32
- "peerDependencies": {
33
- "react": ">=16.8"
34
- },
35
- "devDependencies": {
36
- "@playwright/test": "^1.58.2",
37
- "@types/node": "^25.5.0",
38
- "@types/react": "^19.2.14",
39
- "@types/react-dom": "^19.2.3",
40
- "auxsrv": "^0.3.2",
41
- "immer": "^11.1.4",
42
- "react-dom": "^19.2.4",
43
- "url-shape": "^1.3.15",
44
- "zod": "^4.3.6"
45
- },
46
- "dependencies": {
47
- "stateshape": "^0.2.1"
48
- }
49
- }
1
+ {
2
+ "name": "react-stateshape",
3
+ "version": "0.2.3",
4
+ "description": "A shared state management and routing lib for React apps",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "type": "module",
9
+ "scripts": {
10
+ "demo": "npx auxsrv tests/Shared_state_without_Context",
11
+ "preversion": "npx npm-run-all shape test",
12
+ "shape": "npx codeshape",
13
+ "t3": "npx auxsrv tests/Tic-tac-toe",
14
+ "test": "npx playwright test --project=chromium",
15
+ "typecheck": "npx codeshape typecheck"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/axtk/react-stateshape.git"
20
+ },
21
+ "keywords": [
22
+ "state",
23
+ "state management",
24
+ "react state management",
25
+ "shared state",
26
+ "global state",
27
+ "routing",
28
+ "react router"
29
+ ],
30
+ "license": "MIT",
31
+ "author": "axtk",
32
+ "peerDependencies": {
33
+ "react": ">=16.8"
34
+ },
35
+ "devDependencies": {
36
+ "@playwright/test": "^1.58.2",
37
+ "@types/node": "^25.5.0",
38
+ "@types/react": "^19.2.14",
39
+ "@types/react-dom": "^19.2.3",
40
+ "auxsrv": "^0.3.2",
41
+ "immer": "^11.1.4",
42
+ "react-dom": "^19.2.4",
43
+ "url-shape": "^1.3.15",
44
+ "zod": "^4.3.6"
45
+ },
46
+ "dependencies": {
47
+ "stateshape": "^0.2.1"
48
+ }
49
+ }