redux-astroglide 0.1.7 → 0.1.9
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 +28 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,25 +6,25 @@ Astroglide is a set of configuration and automation tools built on top of Redux
|
|
|
6
6
|
|
|
7
7
|
We stay DRY so you don't have to.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Follow the installation instructions for your app from [@reduxjs/toolkit](https://github.com/reduxjs/redux-toolkit#installation)
|
|
9
|
+
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Installation
|
|
14
12
|
|
|
15
13
|
```bash
|
|
16
14
|
# NPM
|
|
17
|
-
npm install redux-astroglide
|
|
15
|
+
npm install @reduxjs/toolkit redux-astroglide
|
|
18
16
|
|
|
19
17
|
# Yarn
|
|
20
|
-
yarn add redux-astroglide
|
|
18
|
+
yarn add @reduxjs/toolkit redux-astroglide
|
|
21
19
|
|
|
22
20
|
# PNPM
|
|
23
|
-
pnpm add redux-astroglide
|
|
21
|
+
pnpm add @reduxjs/toolkit redux-astroglide
|
|
24
22
|
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
If you're using React, you must also install `react-redux` as a dependency.
|
|
26
|
+
|
|
27
|
+
[@reduxjs/toolkit docs](https://github.com/reduxjs/redux-toolkit#installation)
|
|
28
28
|
|
|
29
29
|
## Setup
|
|
30
30
|
|
|
@@ -64,7 +64,7 @@ export const { useUsername, usePassword } = slice.hooks;
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
Alternatively, you can create the slice using [the same API specified by RTK](https://redux-toolkit.js.org/usage/usage-with-typescript#createslice).
|
|
68
68
|
|
|
69
69
|
```jsx
|
|
70
70
|
const slice = createSlice({
|
|
@@ -82,9 +82,23 @@ const slice = createSlice({
|
|
|
82
82
|
|
|
83
83
|
|
|
84
84
|
|
|
85
|
+
Now wrap your app (or the relevant portion for this redux store) in a Provider from react-redux if you're using React
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
// App.js
|
|
89
|
+
import { Provider } from "react-redux";
|
|
90
|
+
import { store } from "../app/store";
|
|
91
|
+
|
|
92
|
+
export default () => (
|
|
93
|
+
<Provider store={store}>{/* the rest of your app */}</Provider>
|
|
94
|
+
);
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
85
99
|
## Usage
|
|
86
100
|
|
|
87
|
-
|
|
101
|
+
The generated hooks can be used in a React component with the same API as React's setState:
|
|
88
102
|
|
|
89
103
|
```jsx
|
|
90
104
|
export const UsernameField = (props) => {
|
|
@@ -203,9 +217,9 @@ const configure = "redux-astroglide";
|
|
|
203
217
|
export const {
|
|
204
218
|
store,
|
|
205
219
|
createSlice,
|
|
206
|
-
injectReducer,
|
|
207
|
-
injectSlice,
|
|
208
|
-
injectMiddleware,
|
|
220
|
+
injectReducer, // injectReducer(key: string, state => state: reducer fn, optionally async)
|
|
221
|
+
injectSlice, // injectSlice(slice: result from createSlice())
|
|
222
|
+
injectMiddleware, // injectMiddleware(middleware: redux middleware)
|
|
209
223
|
} = configure();
|
|
210
224
|
```
|
|
211
225
|
|
|
@@ -225,7 +239,7 @@ const slice = createSlice("Login", {
|
|
|
225
239
|
// Nav/slice.js
|
|
226
240
|
const slice = createSlice("Nav", {
|
|
227
241
|
isOpen: persist("", {
|
|
228
|
-
storageType: localStorage,
|
|
242
|
+
storageType: localStorage, // default localStorage, must match localStorage API
|
|
229
243
|
}),
|
|
230
244
|
clickCount: set((value) => value + 1),
|
|
231
245
|
});
|