react-reactive-val 1.0.3 → 1.0.5

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 (3) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +139 -0
  3. package/package.json +40 -6
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2024 Jatin Parate
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # React Reactive Val
2
+
3
+ A lightweight, type-safe reactive value management library for React applications. This library provides a simple way to manage reactive values in React components with minimal boilerplate.
4
+
5
+ ## Features
6
+
7
+ - đŸŽ¯ **Type-safe**: Built with TypeScript for excellent type inference
8
+ - đŸĒļ **Lightweight**: Tiny footprint with zero dependencies
9
+ - ⚡ **Fast**: Built on React's `useSyncExternalStore` for optimal performance
10
+ - 🔄 **Reactive**: Values update automatically across components
11
+ - đŸ“Ļ **Tree-shakeable**: Only import what you need
12
+ - đŸŒŗ **Multiple formats**: Supports ESM, CommonJS, and UMD
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install react-reactive-val
18
+ # or
19
+ yarn add react-reactive-val
20
+ # or
21
+ pnpm add react-reactive-val
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Basic Example
27
+
28
+ ```tsx
29
+ import useReactiveValue from 'react-reactive-val';
30
+
31
+ function Counter() {
32
+ const count = useReactiveValue(0);
33
+
34
+ return (
35
+ <div>
36
+ <p>Count: {count()}</p>
37
+ <button onClick={() => count(prev => prev + 1)}>
38
+ Increment
39
+ </button>
40
+ </div>
41
+ );
42
+ }
43
+ ```
44
+
45
+ ### Sharing State Between Components
46
+
47
+ ```tsx
48
+ import { reallyReactiveVal } from 'react-reactive-val';
49
+
50
+ // Create a shared reactive value
51
+ const sharedCount = reallyReactiveVal(0);
52
+
53
+ function CounterDisplay() {
54
+ return <div>Count: {sharedCount()}</div>;
55
+ }
56
+
57
+ function CounterButtons() {
58
+ return (
59
+ <div>
60
+ <button onClick={() => sharedCount(prev => prev + 1)}>
61
+ Increment
62
+ </button>
63
+ <button onClick={() => sharedCount(prev => prev - 1)}>
64
+ Decrement
65
+ </button>
66
+ </div>
67
+ );
68
+ }
69
+ ```
70
+
71
+ ## API Reference
72
+
73
+ ### `useReactiveValue<T>(initialValue: T)`
74
+
75
+ A React hook that creates a reactive value within a component.
76
+
77
+ ```tsx
78
+ const value = useReactiveValue(initialValue);
79
+ ```
80
+
81
+ - `initialValue`: The initial value of the reactive state
82
+ - Returns: A function that can both read and update the value
83
+
84
+ ### `reallyReactiveVal<T>(initialValue: T)`
85
+
86
+ Creates a standalone reactive value that can be used across components.
87
+
88
+ ```tsx
89
+ const value = reallyReactiveVal(initialValue);
90
+ ```
91
+
92
+ - `initialValue`: The initial value of the reactive state
93
+ - Returns: A function that can both read and update the value
94
+
95
+ ### Usage with Value Getter/Setter
96
+
97
+ ```tsx
98
+ // Get the current value
99
+ const currentValue = value();
100
+
101
+ // Set a new value
102
+ value(newValue);
103
+
104
+ // Update based on previous value
105
+ value(prev => computeNewValue(prev));
106
+ ```
107
+
108
+ ## TypeScript Support
109
+
110
+ The library is written in TypeScript and provides full type inference:
111
+
112
+ ```tsx
113
+ // Type is inferred from initial value
114
+ const count = useReactiveValue(0); // type: number
115
+
116
+ // Explicit type annotation
117
+ const user = useReactiveValue<User | null>(null);
118
+
119
+ // Type checking for updates
120
+ user(prev => ({ ...prev, name: "John" })); // Type safe!
121
+ ```
122
+
123
+ ## Contributing
124
+
125
+ Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
126
+
127
+ 1. Fork the repository
128
+ 2. Create your feature branch (\`git checkout -b feature/amazing-feature\`)
129
+ 3. Commit your changes (\`git commit -m 'Add some amazing feature'\`)
130
+ 4. Push to the branch (\`git push origin feature/amazing-feature\`)
131
+ 5. Open a Pull Request
132
+
133
+ ## License
134
+
135
+ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
136
+
137
+ ## Author
138
+
139
+ Jatin Parate ([@jatin4228](https://github.com/jatin4228))
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "react-reactive-val",
3
- "version": "1.0.3",
4
- "description": "",
3
+ "version": "1.0.5",
4
+ "description": "A lightweight, type-safe reactive value management library for React applications",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "types": "./dist/index.d.ts",
10
11
  "import": "./dist/index.esm.js",
11
12
  "require": "./dist/index.cjs.js",
12
13
  "umd": "./dist/index.umd.js"
@@ -20,25 +21,58 @@
20
21
  "build:webpack": "webpack --config webpack.config.js",
21
22
  "build": "rm -rf dist && npm run build:types && npm run build:webpack",
22
23
  "prepublishOnly": "npm run build",
23
- "test": "echo \"Error: no test specified\" && exit 1"
24
+ "test": "echo \"Error: no test specified\" && exit 1",
25
+ "lint": "eslint . --ext .ts,.tsx",
26
+ "format": "prettier --write \"src/**/*.{ts,tsx}\"",
27
+ "prepare": "husky install"
24
28
  },
25
- "peerDependencies": {
26
- "react": "^19.0.0"
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/jatin-parate/react-reactive-val.git"
27
32
  },
28
- "keywords": [],
33
+ "keywords": [
34
+ "react",
35
+ "reactive",
36
+ "state",
37
+ "management",
38
+ "typescript",
39
+ "hooks"
40
+ ],
29
41
  "author": "Jatin Parate <jatin4228@gmail.com>",
30
42
  "license": "ISC",
43
+ "bugs": {
44
+ "url": "https://github.com/jatin-parate/react-reactive-val/issues"
45
+ },
46
+ "homepage": "https://github.com/jatin-parate/react-reactive-val#readme",
47
+ "peerDependencies": {
48
+ "react": "^19.0.0"
49
+ },
31
50
  "devDependencies": {
32
51
  "@babel/core": "^7.24.0",
33
52
  "@babel/preset-env": "^7.24.0",
34
53
  "@babel/preset-react": "^7.23.3",
35
54
  "@babel/preset-typescript": "^7.23.3",
36
55
  "@types/react": "^19.1.0",
56
+ "@typescript-eslint/eslint-plugin": "^7.18.0",
57
+ "@typescript-eslint/parser": "^7.18.0",
37
58
  "babel-loader": "^9.1.3",
59
+ "eslint": "^8.57.1",
60
+ "eslint-config-prettier": "^9.1.0",
61
+ "eslint-plugin-react": "^7.37.5",
62
+ "eslint-plugin-react-hooks": "^4.6.2",
63
+ "husky": "^9.1.7",
64
+ "lint-staged": "^15.5.2",
65
+ "prettier": "^3.5.3",
38
66
  "react": "^19.1.0",
39
67
  "terser-webpack-plugin": "^5.3.10",
40
68
  "typescript": "^5.8.3",
41
69
  "webpack": "^5.90.3",
42
70
  "webpack-cli": "^5.1.4"
71
+ },
72
+ "lint-staged": {
73
+ "*.{ts,tsx}": [
74
+ "eslint --fix",
75
+ "prettier --write"
76
+ ]
43
77
  }
44
78
  }