react-single-instance 0.1.0 → 0.1.1

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 +8 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,7 +4,11 @@
4
4
 
5
5
  Render something at most once for a given `id`, app-wide - a component, a hook, and a HOC, all sharing one registry. Useful for a modal root, a toast host, or any other element that must exist exactly once even if it gets mounted from more than one place by mistake.
6
6
 
7
- Started as a small helper inside [faintlines](https://github.com/itaym/faintlines); this is the standalone, tested, rewritten version.
7
+ | | first claimant | every claimant after it |
8
+ | --- | --- | --- |
9
+ | `<SingleInstance id="x">children</SingleInstance>` | renders `children` | renders nothing |
10
+ | `useSingleInstance('x')` | returns `true` | returns `false` |
11
+ | `withSingleInstance(Component, 'x')` | renders `<Component />` | renders nothing |
8
12
 
9
13
  ```bash
10
14
  npm i react-single-instance
@@ -52,12 +56,14 @@ const GuardedModalHost = withSingleInstance(ModalHost, 'modal-root');
52
56
 
53
57
  ## Playground
54
58
 
55
- A live demo of all three APIs, including the re-render and reset behavior:
59
+ An interactive demo of all three APIs side by side, with the source for each shown right next to it:
56
60
 
57
61
  ```bash
58
62
  npm run playground
59
63
  ```
60
64
 
65
+ Click "mount another claimant" to watch new attempts get rejected live, "re-render" to confirm a granted instance never loses its slot, and "unmount" to see that removing a claimant doesn't free its id - only `initSingleInstance()` does that.
66
+
61
67
  ## Development
62
68
 
63
69
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-single-instance",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Render a component at most once for a given id, app-wide - safely absorbs React.StrictMode's dev double-invoke",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",