context-scoped-state 0.0.3 → 0.0.4

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 +11 -14
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -32,10 +32,11 @@ pnpm add context-scoped-state
32
32
 
33
33
  ## Quick Start
34
34
 
35
- ### 1. Define Your Store
35
+ ### 1. Create Your Store (one file, one export)
36
36
 
37
37
  ```tsx
38
- import { Store } from 'context-scoped-state';
38
+ // stores/counterStore.ts
39
+ import { Store, createStoreHook } from 'context-scoped-state';
39
40
 
40
41
  class CounterStore extends Store<{ count: number }> {
41
42
  protected getInitialState() {
@@ -50,19 +51,16 @@ class CounterStore extends Store<{ count: number }> {
50
51
  this.setState({ count: this.getState().count - 1 });
51
52
  }
52
53
  }
53
- ```
54
-
55
- ### 2. Create the Hook
56
54
 
57
- ```tsx
58
- import { createStoreHook } from 'context-scoped-state';
59
-
60
- const useCounterStore = createStoreHook(CounterStore);
55
+ // This single export is all you need
56
+ export const useCounterStore = createStoreHook(CounterStore);
61
57
  ```
62
58
 
63
- ### 3. Use in Components
59
+ ### 2. Use in Your App
64
60
 
65
61
  ```tsx
62
+ import { useCounterStore } from './stores/counterStore';
63
+
66
64
  function Counter() {
67
65
  const store = useCounterStore();
68
66
 
@@ -75,7 +73,6 @@ function Counter() {
75
73
  );
76
74
  }
77
75
 
78
- // Wrap with Context provider
79
76
  function App() {
80
77
  return (
81
78
  <useCounterStore.Context>
@@ -85,7 +82,7 @@ function App() {
85
82
  }
86
83
  ```
87
84
 
88
- That's it. No providers at the root, no selectors, no reducers, no actions, no dispatch.
85
+ That's it. One hook export gives you the hook and its `.Context` provider. No extra setup needed.
89
86
 
90
87
  ## Examples
91
88
 
@@ -190,8 +187,8 @@ No mocking libraries. No global state cleanup. Just render with the state you ne
190
187
 
191
188
  **vs useState:**
192
189
 
193
- - `useState` binds state logic directly to the component, making it hard to reuse or test independently
194
- - With `context-scoped-state`, state logic lives in a separate class — reusable across components and easily testable
190
+ - `useState` binds state directly to the component poor separation of concerns and hard to test since you can't easily set a component to a specific state
191
+ - Lifting state up with `useState` requires refactoring components and passing props; with `context-scoped-state`, just move the Context wrapper up the tree
195
192
 
196
193
  **vs useReducer:**
197
194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-scoped-state",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {