zeno-state 1.0.0 → 1.0.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 +30 -26
  2. package/package.json +14 -3
package/README.md CHANGED
@@ -1,15 +1,6 @@
1
- # Simple state
1
+ # zeno-state
2
2
 
3
- A (hopefully) simple global state management system.
4
-
5
- ## Demo (this repository)
6
-
7
- 1. Download the code (`git checkout`, or some other way of downloading)
8
- 2. Run `pnpm install`
9
- 3. Run `pnpm run dev`
10
- 4. Open your browser at the location given by pnpm (usually http://localhost:5173)
11
- 5. Open your browser dev tools and enable the React dev tools feature of "Highlight updates when components render."
12
- 6. Have a play and watch how the different start management types handle their rendering
3
+ A simple global state management library for React. Built on React's `useSyncExternalStore`, zeno-state provides a lightweight solution for managing global state with fine-grained re-rendering control through selector functions.
13
4
 
14
5
  ## Installation
15
6
 
@@ -17,13 +8,11 @@ A (hopefully) simple global state management system.
17
8
  npm install zeno-state
18
9
  ```
19
10
 
20
- ## Library usage
11
+ ## Usage
21
12
 
13
+ ### 1. Create a store
22
14
 
23
- ### Step 1: Define a store
24
-
25
- I recommend setting a default value that contains all your keys alongside specifying the shape of the data to help
26
- reduce null value exceptions and to help define the shape of objects contained within empty arrays
15
+ Define your store with an initial state. It's recommended to include all keys in the initial state to help with type inference and avoid null values.
27
16
 
28
17
 
29
18
  ```tsx
@@ -40,10 +29,9 @@ const carStore = createStore<{
40
29
  ```
41
30
 
42
31
 
43
- ### Step 2: Use it
32
+ ### 2. Use the store in components
44
33
 
45
- The second argument of `useStore` is a _selector function_. This allows a portion of the whole state to be used by your
46
- component and enables re-rendering only when that selection changes.
34
+ The `useStore` hook takes two arguments: the store and a selector function. The selector function allows you to subscribe to specific parts of the state, ensuring components only re-render when their selected slice changes.
47
35
 
48
36
  ```tsx
49
37
  import { useStore } from 'zeno-state'
@@ -58,17 +46,33 @@ function CarList() {
58
46
  ```
59
47
 
60
48
 
61
- ### Step 3: Update state inside a store
49
+ ### 3. Update the store
62
50
 
63
- `createStore` returns `get` and `set` methods to update the state, you can use these directly and any components that
64
- have selected part of the state you update will be re-rendered. The `set` function accepts an object which is merged
65
- with the current state object, allowing additions and partial updates to the state.
51
+ The `createStore` function returns `get` and `set` methods. Use `set` to update the state - it accepts a partial state object that gets shallow-merged with the current state. Any components subscribed to the updated slice will automatically re-render.
66
52
 
67
- > Note: this only allows for updating and adding keys to the stored state, not deleting any root-level keys not directly
68
- > updating deep-nested properties.
53
+ **Note:** The `set` method uses shallow merging, so nested objects need to be explicitly spread for updates.
69
54
 
70
55
  ```tsx
71
56
  function addCar() {
72
- carStore.set({ cars: [...cars, { make: 'Ford', model: 'Focus', engineSize: 1.6, colour: 'silver'}]})
57
+ const currentCars = carStore.get().cars
58
+ carStore.set({
59
+ cars: [...currentCars, {
60
+ make: 'Ford',
61
+ model: 'Focus',
62
+ engineSize: 1.6,
63
+ colour: 'silver'
64
+ }]
65
+ })
73
66
  }
74
67
  ```
68
+
69
+ ## Features
70
+
71
+ - **Lightweight** - Minimal API surface with just `createStore` and `useStore`
72
+ - **Fine-grained updates** - Selector functions ensure components only re-render when their selected state changes
73
+ - **TypeScript support** - Full type safety with TypeScript
74
+ - **React 18/19 compatible** - Built on React's `useSyncExternalStore` hook
75
+
76
+ ## License
77
+
78
+ MIT
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "zeno-state",
3
3
  "private": false,
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
5
  "type": "module",
6
6
  "description": "A simple global state management library for React",
7
- "keywords": ["react", "state", "state-management", "hooks", "global-state"],
7
+ "keywords": [
8
+ "react",
9
+ "state",
10
+ "state-management",
11
+ "hooks",
12
+ "global-state"
13
+ ],
8
14
  "author": "Rob Watson",
9
15
  "license": "MIT",
10
16
  "main": "./dist/index.js",
@@ -15,7 +21,11 @@
15
21
  "import": "./dist/index.js"
16
22
  }
17
23
  },
18
- "files": ["dist", "README.md", "LICENSE"],
24
+ "files": [
25
+ "dist",
26
+ "README.md",
27
+ "LICENSE"
28
+ ],
19
29
  "scripts": {
20
30
  "dev": "vite",
21
31
  "build": "tsc -b && vite build",
@@ -30,6 +40,7 @@
30
40
  "devDependencies": {
31
41
  "@eslint/js": "^9.19.0",
32
42
  "@tailwindcss/vite": "^4.0.6",
43
+ "@types/node": "^25.3.0",
33
44
  "@types/react": "^19.0.8",
34
45
  "@types/react-dom": "^19.0.3",
35
46
  "@vitejs/plugin-react": "^4.3.4",