react-stateshape 0.2.1 → 0.2.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.
Files changed (2) hide show
  1. package/README.md +9 -6
  2. package/package.json +2 -2
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
  // ...
@@ -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` and the other routing hooks described here make 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,7 +1,7 @@
1
1
  {
2
2
  "name": "react-stateshape",
3
- "version": "0.2.1",
4
- "description": "Concise shared state management and routing in React apps",
3
+ "version": "0.2.2",
4
+ "description": "A shared state management and routing lib for React apps",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",