reactish-state 1.0.0-alpha.2 → 1.0.0-alpha.3

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 +19 -7
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  > Simple, decentralized (atomic) state management for React.
4
4
 
5
- [![NPM](https://img.shields.io/npm/v/reactish-state.svg)](https://www.npmjs.com/package/reactish-state) [![NPM](https://img.shields.io/bundlephobia/minzip/reactish-state)](https://bundlephobia.com/package/reactish-state)
5
+ [![NPM](https://img.shields.io/npm/v/reactish-state.svg)](https://www.npmjs.com/package/reactish-state) [![NPM](https://img.shields.io/bundlephobia/minzip/reactish-state)](https://bundlephobia.com/package/reactish-state) [![bundlejs](https://img.shields.io/badge/bundlejs-.com-blue.svg)](https://bundlejs.com/?q=reactish-state&treeshake=%5B*%5D&config=%7B%22esbuild%22%3A%7B%22external%22%3A%5B%22react%22%5D%7D%7D)
6
+
7
+ 💡 [Quick examples](#examples)    🔧 [TypeScript usage](#typescript-usage)
6
8
 
7
9
  ## ✨Highlights✨
8
10
 
@@ -600,6 +602,16 @@ The API relies on type inference to correctly infer the types for both the value
600
602
 
601
603
  In this case, the usage in TypeScript should be identical to JavaScript. You don't need to make any specific effort regarding typing. This is true when the state holds simple or primitive values.
602
604
 
605
+ ```ts
606
+ const countState = state(0, (set) => ({
607
+ increase: (by: number) =>
608
+ set(
609
+ (count) => count + by
610
+ // The `count` is inferred as a number type from the initial value.
611
+ )
612
+ }));
613
+ ```
614
+
603
615
  ## II. The type of state cannot be inferred from its initial value
604
616
 
605
617
  In this case, you have three options:
@@ -638,6 +650,12 @@ const myTodos = state<string[], { add: (newTodo: string) => void }>(
638
650
 
639
651
  However, if you choose this method, you need to specify the types for both the state value and actions.
640
652
 
653
+ # Examples
654
+
655
+ - Counter – [sandbox](https://codesandbox.io/p/sandbox/reactish-counter-z42qt7) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/counter)
656
+ - Todo app – [sandbox](https://codesandbox.io/s/reactish-todo-thyhbl) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/todo)
657
+ - Async – [sandbox](https://codesandbox.io/s/reactish-async-2cghkg) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/async)
658
+
641
659
  # React 16/17 setup
642
660
 
643
661
  When using this library with React 16/17, you must set up a shim since it doesn't include a native [useSyncExternalStore](https://react.dev/reference/react/useSyncExternalStore). We don't set up the shim by default to minimize the bundle size for React 18/19 users.
@@ -649,9 +667,3 @@ setReactShim(reactShim);
649
667
  ```
650
668
 
651
669
  You only need to set it up once after your app launches, outside of React code. DO NOT call `setReactShim` within any React components.
652
-
653
- # Examples
654
-
655
- - Counter – [sandbox](https://codesandbox.io/p/sandbox/reactish-counter-z42qt7) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/counter)
656
- - Todo app – [sandbox](https://codesandbox.io/s/reactish-todo-thyhbl) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/todo)
657
- - Async – [sandbox](https://codesandbox.io/s/reactish-async-2cghkg) | [source](https://github.com/szhsin/reactish-state/tree/master/examples/examples/async)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactish-state",
3
- "version": "1.0.0-alpha.2",
4
- "description": "Simple, decentralized state management for React.",
3
+ "version": "1.0.0-alpha.3",
4
+ "description": "Simple, decentralized (atomic) state management for React.",
5
5
  "author": "Zheng Song",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "lint:fix": "eslint --fix .",
38
38
  "pret": "prettier -c .",
39
39
  "pret:fix": "prettier -w .",
40
- "build": "run-s pret lint clean types bundle",
40
+ "build": "run-s pret clean types lint bundle",
41
41
  "test": "jest",
42
42
  "test:watch": "jest --watch",
43
43
  "eg": "npm run dev --prefix examples"