@t8/react-store 1.0.33 → 1.0.35

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 CHANGED
@@ -1,10 +1,8 @@
1
- [![npm](https://flat.badgen.net/npm/v/@t8/react-store?labelColor=345&color=46e)](https://www.npmjs.com/package/@t8/react-store) ![Lightweight](https://flat.badgen.net/bundlephobia/minzip/@t8/react-store/?label=minzip&labelColor=345&color=46e) ![TypeScript ✓](https://flat.badgen.net/badge/TypeScript/✓?labelColor=345&color=345) ![CSR ✓](https://flat.badgen.net/badge/CSR/✓?labelColor=345&color=345) ![SSR ✓](https://flat.badgen.net/badge/SSR/✓?labelColor=345&color=345)
1
+ # T8 React Store
2
2
 
3
- # @t8/react-store
3
+ *`useState()`-like React app state management*
4
4
 
5
- *Concise shared state management for React apps*
6
-
7
- 🔹 Similar to `useState()`
5
+ [![npm](https://img.shields.io/npm/v/@t8/react-store?labelColor=345&color=46e)](https://www.npmjs.com/package/@t8/react-store) ![Lightweight](https://img.shields.io/bundlephobia/minzip/@t8/react-store?label=minzip&labelColor=345&color=46e) ![CSR ✓](https://img.shields.io/badge/CSR-✓-345?labelColor=345) ![SSR ✓](https://img.shields.io/badge/SSR-✓-345?labelColor=345)
8
6
 
9
7
  ```diff
10
8
  + let store = new Store(0);
@@ -21,9 +19,11 @@
21
19
  };
22
20
  ```
23
21
 
24
- 🔹 No boilerplate<br>
25
- 🔹 Painless transition from local state<br>
26
- 🔹 SSR- and CSR-compatible
22
+ - Similar to `useState()`
23
+ - No boilerplate
24
+ - Quick transition from local state
25
+ - Easily integrates with Immer
26
+ - SSR- and CSR-compatible
27
27
 
28
28
  Installation: `npm i @t8/react-store`
29
29
 
@@ -0,0 +1,2 @@
1
+ export * from "@t8/store";
2
+ export * from "./src/useStore.ts";
@@ -0,0 +1,25 @@
1
+ import { type Store } from "@t8/store";
2
+ export type SetStoreState<T> = Store<T>["setState"];
3
+ export type ShouldUpdateCallback<T> = (nextState: T, prevState: T) => boolean;
4
+ export type ShouldUpdate<T> = boolean | ShouldUpdateCallback<T>;
5
+ export declare function useStore<T>(store: Store<T>,
6
+ /**
7
+ * Controls whether the component should be updated in response
8
+ * to the store updates.
9
+ *
10
+ * @defaultValue `true`
11
+ *
12
+ * `shouldUpdate` can be set to `false` to prevent subscription
13
+ * to the store updates. Use case: when the component only requires
14
+ * the store state setter but not the store state value, the
15
+ * component may not need to respond to the store updates:
16
+ *
17
+ * ```ts
18
+ * let [, setValue] = useStore(store, false);
19
+ * ```
20
+ *
21
+ * `shouldUpdate` can be set to a function `(nextState, prevState) => boolean`
22
+ * to make the component respond only to specific store state changes,
23
+ * when this function returns `true`.
24
+ */
25
+ shouldUpdate?: ShouldUpdate<T>): [T, SetStoreState<T>];
package/package.json CHANGED
@@ -1,49 +1,51 @@
1
- {
2
- "name": "@t8/react-store",
3
- "version": "1.0.33",
4
- "description": "Concise shared state management for React apps",
5
- "main": "dist/index.js",
6
- "type": "module",
7
- "scripts": {
8
- "build": "npx npm-run-all clean compile",
9
- "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
10
- "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral --external:react",
11
- "demo": "npx @t8/serve 3000 * tests/counter -b src/index.tsx",
12
- "prepublishOnly": "npm run build",
13
- "preversion": "npx npm-run-all typecheck shape build test",
14
- "shape": "npx codeshape",
15
- "test": "npx playwright test --project=chromium",
16
- "tic-tac-toe": "npx @t8/serve 3000 * tests/tic-tac-toe -b src/index.tsx",
17
- "typecheck": "tsc --noEmit"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/t8js/react-store.git"
22
- },
23
- "homepage": "https://t8.js.org/react-store",
24
- "keywords": [
25
- "react",
26
- "state management",
27
- "shared state",
28
- "global state",
29
- "store"
30
- ],
31
- "author": "axtk",
32
- "license": "MIT",
33
- "peerDependencies": {
34
- "react": ">=16.8"
35
- },
36
- "devDependencies": {
37
- "@playwright/test": "^1.56.0",
38
- "@t8/serve": "^0.1.34",
39
- "@types/node": "^24.5.2",
40
- "@types/react": "^19.1.10",
41
- "@types/react-dom": "^19.1.9",
42
- "immer": "^10.1.3",
43
- "react-dom": "^19.1.1",
44
- "typescript": "^5.9.3"
45
- },
46
- "dependencies": {
47
- "@t8/store": "^1.1.7"
48
- }
49
- }
1
+ {
2
+ "name": "@t8/react-store",
3
+ "version": "1.0.35",
4
+ "description": "useState()-like React app state management",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "npx npm-run-all clean compile types",
10
+ "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
11
+ "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=neutral --external:react",
12
+ "demo": "npx @t8/serve 3000 * tests/counter -b src/index.tsx",
13
+ "prepublishOnly": "npm run build",
14
+ "preversion": "npx npm-run-all typecheck shape build test",
15
+ "shape": "npx codeshape",
16
+ "test": "npx playwright test --project=chromium",
17
+ "tic-tac-toe": "npx @t8/serve 3000 * tests/tic-tac-toe -b src/index.tsx",
18
+ "typecheck": "tsc --noEmit",
19
+ "types": "tsc -p tsconfig.build.json"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/t8js/react-store.git"
24
+ },
25
+ "homepage": "https://t8.js.org/react-store",
26
+ "keywords": [
27
+ "react",
28
+ "state management",
29
+ "shared state",
30
+ "global state",
31
+ "store"
32
+ ],
33
+ "author": "axtk",
34
+ "license": "MIT",
35
+ "peerDependencies": {
36
+ "react": ">=16.8"
37
+ },
38
+ "devDependencies": {
39
+ "@playwright/test": "^1.56.0",
40
+ "@t8/serve": "^0.1.34",
41
+ "@types/node": "^24.5.2",
42
+ "@types/react": "^19.1.10",
43
+ "@types/react-dom": "^19.1.9",
44
+ "immer": "^10.1.3",
45
+ "react-dom": "^19.1.1",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "dependencies": {
49
+ "@t8/store": "^1.1.10"
50
+ }
51
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["./index.ts", "./src"]
4
+ }
package/tsconfig.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "include": ["./index.ts", "./playwright.config.ts", "./src", "./tests"],
3
3
  "compilerOptions": {
4
- "noEmit": true,
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
5
6
  "jsx": "react-jsx",
6
7
  "lib": ["ESNext", "DOM"],
7
8
  "target": "esnext",