redux-simplify-hooks 1.0.0 → 1.0.1
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/LICENSE +17 -17
- package/README.md +147 -147
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
Copyright 2025 Mbulelo Phillip Peyi
|
|
6
|
-
|
|
7
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
you may not use this file except in compliance with the License.
|
|
9
|
-
You may obtain a copy of the License at
|
|
10
|
-
|
|
11
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
|
|
13
|
-
Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
See the License for the specific language governing permissions and
|
|
17
|
-
limitations under the License.
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Copyright 2025 Mbulelo Phillip Peyi
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
See the License for the specific language governing permissions and
|
|
17
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,147 +1,147 @@
|
|
|
1
|
-
Excellent — let’s write a **professional `README.md`** for your package `redux-simplify-hooks`:
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
````markdown
|
|
6
|
-
# redux-simplify-hooks
|
|
7
|
-
|
|
8
|
-
> Redux made simple: modern, type-safe React hooks for deeply nested state, actions, and selectors — fully compatible with Redux Toolkit and React 16.8+.
|
|
9
|
-
|
|
10
|
-
[](LICENSE)
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
**redux-simplify-hooks** is a lightweight collection of hooks that simplifies working with Redux state in React.
|
|
17
|
-
It provides ergonomic and modern alternatives to `useSelector` and `useDispatch`, allowing you to:
|
|
18
|
-
|
|
19
|
-
- Select deeply nested state using dot notation.
|
|
20
|
-
- Read and write Redux state like React’s `useState()`.
|
|
21
|
-
- Bind Redux actions easily with hooks.
|
|
22
|
-
- Select multiple state slices at once.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
|
|
33
|
-
First install the required peer dependencies if not already installed:
|
|
34
|
-
|
|
35
|
-
```bash
|
|
36
|
-
npm install react react-dom react-redux @reduxjs/toolkit
|
|
37
|
-
````
|
|
38
|
-
|
|
39
|
-
Then install redux-simplify-hooks:
|
|
40
|
-
|
|
41
|
-
```bash
|
|
42
|
-
npm install redux-simplify-hooks
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## ⚙ Peer Dependencies
|
|
48
|
-
|
|
49
|
-
| Package | Version |
|
|
50
|
-
| ---------------- | ---------------------- |
|
|
51
|
-
| react | >= 16.8 |
|
|
52
|
-
| react-dom | >= 16.8 |
|
|
53
|
-
| react-redux | ^7.1.0, ^8.0.0, ^9.0.0 |
|
|
54
|
-
| @reduxjs/toolkit | >= 1.0.0 |
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
### 1
|
|
61
|
-
|
|
62
|
-
Read nested state using dot-path notation:
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
import { useRedux } from 'redux-simplify-hooks';
|
|
66
|
-
|
|
67
|
-
const MyComponent = () => {
|
|
68
|
-
const { state, dispatch } = useRedux('user.profile.name');
|
|
69
|
-
|
|
70
|
-
return <div>Hello, {state}</div>;
|
|
71
|
-
};
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 2
|
|
75
|
-
|
|
76
|
-
Select multiple state paths at once:
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
import { useReduxMulti } from 'redux-simplify-hooks';
|
|
80
|
-
|
|
81
|
-
const { state } = useReduxMulti(['user.profile.name', 'counter.value']);
|
|
82
|
-
|
|
83
|
-
console.log(state['user.profile.name']);
|
|
84
|
-
console.log(state['counter.value']);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 3
|
|
88
|
-
|
|
89
|
-
Read & write Redux state like React's `useState`:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
import { useReduxState } from 'redux-simplify-hooks';
|
|
93
|
-
import { counterSlice } from './counterSlice';
|
|
94
|
-
|
|
95
|
-
const [count, setCount] = useReduxState('counter.value', counterSlice.actions.setCounter);
|
|
96
|
-
|
|
97
|
-
setCount(42);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
### 4
|
|
101
|
-
|
|
102
|
-
Bind Redux actions to dispatch automatically:
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
import { useBoundAction } from 'redux-simplify-hooks';
|
|
106
|
-
import { counterSlice } from './counterSlice';
|
|
107
|
-
|
|
108
|
-
const incrementByAmount = useBoundAction(counterSlice.actions.incrementByAmount);
|
|
109
|
-
|
|
110
|
-
incrementByAmount(5); // dispatches action
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
##
|
|
116
|
-
|
|
117
|
-
redux-simplify-hooks is fully tested using:
|
|
118
|
-
|
|
119
|
-
* Jest
|
|
120
|
-
* @testing-library/react
|
|
121
|
-
|
|
122
|
-
```bash
|
|
123
|
-
npm run test
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
##
|
|
129
|
-
|
|
130
|
-
This project is licensed under the **Apache License 2.0**.
|
|
131
|
-
|
|
132
|
-
© 2025 Mbulelo Phillip Peyi
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
##
|
|
137
|
-
|
|
138
|
-
Redux can be powerful but verbose — **redux-simplify-hooks** aims to make Redux feel as simple as React's `useState()` without sacrificing its robustness.
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
##
|
|
143
|
-
|
|
144
|
-
PRs and issues are welcome! If you want to contribute, please fork and submit a pull request.
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
1
|
+
Excellent — let’s write a **professional `README.md`** for your package `redux-simplify-hooks`:
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
````markdown
|
|
6
|
+
# redux-simplify-hooks
|
|
7
|
+
|
|
8
|
+
> Redux made simple: modern, type-safe React hooks for deeply nested state, actions, and selectors — fully compatible with Redux Toolkit and React 16.8+.
|
|
9
|
+
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## What is redux-simplify-hooks?
|
|
15
|
+
|
|
16
|
+
**redux-simplify-hooks** is a lightweight collection of hooks that simplifies working with Redux state in React.
|
|
17
|
+
It provides ergonomic and modern alternatives to `useSelector` and `useDispatch`, allowing you to:
|
|
18
|
+
|
|
19
|
+
- Select deeply nested state using dot notation.
|
|
20
|
+
- Read and write Redux state like React’s `useState()`.
|
|
21
|
+
- Bind Redux actions easily with hooks.
|
|
22
|
+
- Select multiple state slices at once.
|
|
23
|
+
|
|
24
|
+
Fully type-safe
|
|
25
|
+
Compatible with **React 16.8+** (Hooks onward)
|
|
26
|
+
Compatible with **Redux Toolkit**
|
|
27
|
+
Supports React 17, 18, 19+
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
First install the required peer dependencies if not already installed:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install react react-dom react-redux @reduxjs/toolkit
|
|
37
|
+
````
|
|
38
|
+
|
|
39
|
+
Then install redux-simplify-hooks:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install redux-simplify-hooks
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## ⚙ Peer Dependencies
|
|
48
|
+
|
|
49
|
+
| Package | Version |
|
|
50
|
+
| ---------------- | ---------------------- |
|
|
51
|
+
| react | >= 16.8 |
|
|
52
|
+
| react-dom | >= 16.8 |
|
|
53
|
+
| react-redux | ^7.1.0, ^8.0.0, ^9.0.0 |
|
|
54
|
+
| @reduxjs/toolkit | >= 1.0.0 |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### 1 `useRedux()`
|
|
61
|
+
|
|
62
|
+
Read nested state using dot-path notation:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
import { useRedux } from 'redux-simplify-hooks';
|
|
66
|
+
|
|
67
|
+
const MyComponent = () => {
|
|
68
|
+
const { state, dispatch } = useRedux('user.profile.name');
|
|
69
|
+
|
|
70
|
+
return <div>Hello, {state}</div>;
|
|
71
|
+
};
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 2 `useReduxMulti()`
|
|
75
|
+
|
|
76
|
+
Select multiple state paths at once:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { useReduxMulti } from 'redux-simplify-hooks';
|
|
80
|
+
|
|
81
|
+
const { state } = useReduxMulti(['user.profile.name', 'counter.value']);
|
|
82
|
+
|
|
83
|
+
console.log(state['user.profile.name']);
|
|
84
|
+
console.log(state['counter.value']);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 3 `useReduxState()`
|
|
88
|
+
|
|
89
|
+
Read & write Redux state like React's `useState`:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { useReduxState } from 'redux-simplify-hooks';
|
|
93
|
+
import { counterSlice } from './counterSlice';
|
|
94
|
+
|
|
95
|
+
const [count, setCount] = useReduxState('counter.value', counterSlice.actions.setCounter);
|
|
96
|
+
|
|
97
|
+
setCount(42);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4 `useBoundAction()`
|
|
101
|
+
|
|
102
|
+
Bind Redux actions to dispatch automatically:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { useBoundAction } from 'redux-simplify-hooks';
|
|
106
|
+
import { counterSlice } from './counterSlice';
|
|
107
|
+
|
|
108
|
+
const incrementByAmount = useBoundAction(counterSlice.actions.incrementByAmount);
|
|
109
|
+
|
|
110
|
+
incrementByAmount(5); // dispatches action
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Testing
|
|
116
|
+
|
|
117
|
+
redux-simplify-hooks is fully tested using:
|
|
118
|
+
|
|
119
|
+
* Jest
|
|
120
|
+
* @testing-library/react
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm run test
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
This project is licensed under the **Apache License 2.0**.
|
|
131
|
+
|
|
132
|
+
© 2025 Mbulelo Phillip Peyi
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Motivation
|
|
137
|
+
|
|
138
|
+
Redux can be powerful but verbose — **redux-simplify-hooks** aims to make Redux feel as simple as React's `useState()` without sacrificing its robustness.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Contributions
|
|
143
|
+
|
|
144
|
+
PRs and issues are welcome! If you want to contribute, please fork and submit a pull request.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-simplify-hooks",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Redux made simple: modern, type-safe React hooks for deeply nested state, actions, and selectors — fully compatible with Redux Toolkit and React 16.8+.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|