@createstore/createstore 0.0.0 → 1.0.0

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
@@ -24,6 +24,28 @@ function Counter() {
24
24
  Every component that reads `'count'` re-renders when any of them changes it. Outside React, use
25
25
  `store.getState('count')` and `store.setState('count', 2)`.
26
26
 
27
+ ### Share state between components
28
+
29
+ Take `useGlobalState` out of the store, and any component can read or change the same list. No provider, no props
30
+ passed down:
31
+
32
+ ```tsx
33
+ const { useGlobalState } = createStore({ todos: [] as { text: string }[] });
34
+
35
+ function TodoCount() {
36
+ const [todos] = useGlobalState('todos');
37
+ return <p>{todos.length} todos</p>;
38
+ }
39
+
40
+ function AddTodo() {
41
+ const [todos, setTodos] = useGlobalState('todos');
42
+ const add = (text: string) => setTodos([...todos, { text }]);
43
+ return <Form onAdd={add} />;
44
+ }
45
+ ```
46
+
47
+ `<Form>` stands for your own form component. When `AddTodo` adds a todo, `TodoCount` updates by itself.
48
+
27
49
  Everything else stays off until you use it: computed values, server data with `query()`, persistence, offline
28
50
  support, undo/redo, tab sync, events and server rendering.
29
51
 
@@ -33,6 +55,14 @@ support, undo/redo, tab sync, events and server rendering.
33
55
  - Published with [npm provenance](https://docs.npmjs.com/generating-provenance-statements).
34
56
  - Versioned with [semantic versioning](https://semver.org); see [CHANGELOG.md](./CHANGELOG.md) once a release exists.
35
57
 
58
+ ## Links
59
+
60
+ - [GitHub repository](https://github.com/Gauravasawa/createstore): source code, issues and releases
61
+ - [npm package](https://www.npmjs.com/package/@createstore/createstore)
62
+ - [Documentation](https://createstore-docs.pages.dev)
63
+ - [Report a bug or request a feature](https://github.com/Gauravasawa/createstore/issues/new/choose)
64
+ - [Security policy](https://github.com/Gauravasawa/createstore/security/policy)
65
+
36
66
  ## License
37
67
 
38
68
  [MIT](./LICENSE)