react-state-bucket 1.1.0 β†’ 1.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +131 -135
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.1.1",
3
3
  "name": "react-state-bucket",
4
4
  "author": "Naxrul Ahmed",
5
5
  "license": "MIT",
package/readme.md CHANGED
@@ -4,192 +4,174 @@
4
4
 
5
5
  <h1 align="center">React State Bucket</h1>
6
6
 
7
+ Effortlessly manage React application states with **react-state-bucket**, a lightweight yet powerful state management library.
7
8
 
8
- `react-state-bucket` is a lightweight and powerful package designed to manage states globally in React applications. It provides CRUD operations for your state data with ease, enabling developers to handle complex state management scenarios without the need for heavy libraries.
9
+ ---
9
10
 
10
- This package supports multiple storage options, including:
11
+ ## πŸš€ Features
11
12
 
12
- - Memory (default)
13
- - Session Storage
14
- - Local Storage
15
- - URL Query Parameters
13
+ - **Global State Management**: Manage state across your entire React application with ease.
14
+ - **CRUD Operations**: Create, Read, Update, and Delete state values effortlessly.
15
+ - **Multiple Storage Options**: Store state in "memory," "session storage," "local storage," or "URL parameters."
16
+ - **Reactivity**: Automatically update components when the state changes.
17
+ - **Custom Hooks**: Seamlessly integrate with React’s functional components.
18
+ - **TypeScript Support**: Fully typed for a better development experience.
19
+ - **Lightweight**: Small bundle size with no unnecessary dependencies.
16
20
 
17
- ## Installation
21
+ ---
22
+
23
+ ## πŸ“¦ Installation
24
+
25
+ Install the package via npm or yarn:
18
26
 
19
27
  ```bash
28
+ # Using npm
20
29
  npm install react-state-bucket
30
+
31
+ # Using yarn
32
+ yarn add react-state-bucket
21
33
  ```
22
34
 
23
- ## Features
35
+ ---
24
36
 
25
- - **Global State Management**: Easily manage state across your entire React application.
26
- - **CRUD Operations**: Create, Read, Update, and Delete state values effortlessly.
27
- - **Multiple Storage Options**: Choose where to store your data ("memory", "session", "local", or "url").
28
- - **Reactivity**: Automatically update components when the state changes.
29
- - **Custom Hooks**: Seamlessly integrate with React’s functional components.
37
+ ## πŸ”§ Setup and Usage
30
38
 
31
- ## Usage
39
+ ### Step 1: Create a State Bucket
32
40
 
33
- ### Basic Example
41
+ Define your initial state and actions:
34
42
 
35
- ```jsx
36
- "use client";
43
+ ```javascript
44
+ import { createBucket } from 'react-state-bucket';
37
45
 
38
- import React from "react";
39
- import {createBucket} from "react-state-bucket";
46
+ const initialState = {
47
+ count: 0,
48
+ user: 'Guest',
49
+ };
40
50
 
41
- // Create a bucket with initial state
42
- const useGlobalState = createBucket({ count: 0, user: "Guest" });
51
+ export const useGlobalState = createBucket(initialState);
52
+ ```
43
53
 
44
- function App() {
45
- const globalState = useGlobalState();
46
-
47
- return (
48
- <div>
49
- <h1>Global State Management</h1>
50
- <p>Count: {globalState.get("count")}</p>
51
- <button onClick={() => globalState.set("count", globalState.get("count") + 1)}>Increment</button>
52
- <button onClick={() => globalState.delete("count")}>Reset Count</button>
53
- <pre>{JSON.stringify(globalState.getState(), null, 2)}</pre>
54
- </div>
55
- );
56
- }
54
+ ### Step 2: Use the State Bucket in a Component
55
+
56
+ Access state and actions in your React components:
57
+
58
+ ```javascript
59
+ import React from 'react';
60
+ import { useGlobalState } from './state';
61
+
62
+ const App = () => {
63
+ const globalState = useGlobalState();
64
+
65
+ return (
66
+ <div>
67
+ <h1>Global State Management</h1>
68
+ <p>Count: {globalState.get('count')}</p>
69
+ <button onClick={() => globalState.set('count', globalState.get('count') + 1)}>Increment</button>
70
+ <button onClick={() => globalState.delete('count')}>Reset Count</button>
71
+ <pre>{JSON.stringify(globalState.getState(), null, 2)}</pre>
72
+ </div>
73
+ );
74
+ };
57
75
 
58
76
  export default App;
59
77
  ```
60
78
 
79
+ ---
80
+
81
+ ## 🌟 Advanced Features
82
+
61
83
  ### Using Multiple Buckets
62
84
 
63
- ```jsx
64
- const useUserBucket = createBucket({ name: "", age: 0 });
65
- const useSettingsBucket = createBucket({ theme: "light", notifications: true });
85
+ ```javascript
86
+ const useUserBucket = createBucket({ name: '', age: 0 });
87
+ const useSettingsBucket = createBucket({ theme: 'light', notifications: true });
66
88
 
67
89
  function Profile() {
68
- const userBucket = useUserBucket();
69
- const settingsBucket = useSettingsBucket();
70
-
71
- return (
72
- <div>
73
- <h1>User Profile</h1>
74
- <button onClick={() => userBucket.set("name", "John Doe")}>Set Name</button>
75
- <button onClick={() => settingsBucket.set("theme", "dark")}>Change Theme</button>
76
- <pre>User State: {JSON.stringify(userBucket.getState(), null, 2)}</pre>
77
- <p>Current Theme: {settingsBucket.get("theme")}</p>
78
- </div>
79
- );
90
+ const userBucket = useUserBucket();
91
+ const settingsBucket = useSettingsBucket();
92
+
93
+ return (
94
+ <div>
95
+ <h1>User Profile</h1>
96
+ <button onClick={() => userBucket.set('name', 'John Doe')}>Set Name</button>
97
+ <button onClick={() => settingsBucket.set('theme', 'dark')}>Change Theme</button>
98
+ <pre>User State: {JSON.stringify(userBucket.getState(), null, 2)}</pre>
99
+ <p>Current Theme: {settingsBucket.get('theme')}</p>
100
+ </div>
101
+ );
80
102
  }
81
103
  ```
82
104
 
83
- ### Storage Options Example
105
+ ### Persistent Storage Options
84
106
 
85
- ```jsx
107
+ ```javascript
86
108
  const usePersistentBucket = createBucket(
87
- { token: "", language: "en" },
88
- { store: "local" }
109
+ { token: '', language: 'en' },
110
+ { store: 'local' }
89
111
  );
90
112
 
91
113
  function PersistentExample() {
92
- const persistentBucket = usePersistentBucket();
93
-
94
- return (
95
- <div>
96
- <h1>Persistent Bucket</h1>
97
- <button onClick={() => persistentBucket.set("token", "abc123")}>Set Token</button>
98
- <p>Token: {persistentBucket.get("token")}</p>
99
- </div>
100
- );
114
+ const persistentBucket = usePersistentBucket();
115
+
116
+ return (
117
+ <div>
118
+ <h1>Persistent Bucket</h1>
119
+ <button onClick={() => persistentBucket.set('token', 'abc123')}>Set Token</button>
120
+ <p>Token: {persistentBucket.get('token')}</p>
121
+ </div>
122
+ );
101
123
  }
102
124
  ```
103
125
 
104
126
  ### Reusing State Across Components
105
127
 
106
- ```jsx
107
- "use client";
108
-
109
- import React from "react";
110
- import {createBucket} from "react-state-bucket";
128
+ ```javascript
129
+ import React from 'react';
130
+ import { createBucket } from 'react-state-bucket';
111
131
 
112
- // Create a global bucket
113
- const useGlobalState = createBucket({ count: 0, user: "Guest" });
132
+ const useGlobalState = createBucket({ count: 0, user: 'Guest' });
114
133
 
115
134
  function Counter() {
116
- const globalState = useGlobalState(); // Access bucket functions and trigger re-render on state updates
117
-
118
- return (
119
- <div>
120
- <h2>Counter Component</h2>
121
- <p>Count: {globalState.get("count")}</p>
122
- <button onClick={() => globalState.set("count", globalState.get("count") + 1)}>
123
- Increment Count
124
- </button>
125
- </div>
126
- );
135
+ const globalState = useGlobalState();
136
+
137
+ return (
138
+ <div>
139
+ <h2>Counter Component</h2>
140
+ <p>Count: {globalState.get('count')}</p>
141
+ <button onClick={() => globalState.set('count', globalState.get('count') + 1)}>Increment Count</button>
142
+ </div>
143
+ );
127
144
  }
128
145
 
129
146
  function UserDisplay() {
130
- const globalState = useGlobalState(); // Reuse the same global bucket for reactivity
131
-
132
- return (
133
- <div>
134
- <h2>User Component</h2>
135
- <p>Current User: {globalState.get("user")}</p>
136
- <button onClick={() => globalState.set("user", "John Doe")}>
137
- Set User to John Doe
138
- </button>
139
- </div>
140
- );
147
+ const globalState = useGlobalState();
148
+
149
+ return (
150
+ <div>
151
+ <h2>User Component</h2>
152
+ <p>Current User: {globalState.get('user')}</p>
153
+ <button onClick={() => globalState.set('user', 'John Doe')}>Set User to John Doe</button>
154
+ </div>
155
+ );
141
156
  }
142
157
 
143
158
  function App() {
144
-
145
- return (
146
- <div>
147
- <h1>Global State Example</h1>
148
- <Counter />
149
- <UserDisplay />
150
- <pre>Global State: {JSON.stringify(useGlobalState().getState(), null, 2)}</pre>
151
- </div>
152
- );
159
+ return (
160
+ <div>
161
+ <h1>Global State Example</h1>
162
+ <Counter />
163
+ <UserDisplay />
164
+ <pre>Global State: {JSON.stringify(useGlobalState().getState(), null, 2)}</pre>
165
+ </div>
166
+ );
153
167
  }
154
168
 
155
169
  export default App;
156
170
  ```
157
171
 
158
- ## Direct Usage of Functions
159
-
160
- The `createBucket` function provides direct access to the state management methods like `get`, `set`, `delete`, and others. For components that require re-rendering when the state changes, call the custom hook returned by `createBucket` within the component.
161
-
162
- ### Example
172
+ ---
163
173
 
164
- ```jsx
165
- const useGlobalState = createBucket({ count: 0, user: "Guest" });
166
-
167
- function Counter() {
168
-
169
- return (
170
- <div>
171
- <p>Count: {useGlobalState.get("count")}</p>
172
- <button onClick={() => useGlobalState.set("count", useGlobalState.get("count") + 1)}>Increment</button>
173
- </div>
174
- );
175
- }
176
-
177
- function App() {
178
- useGlobalState(); // Will automatically re-render when state updates
179
-
180
- return (
181
- <div>
182
- <Counter />
183
- </div>
184
- );
185
- }
186
-
187
- export default App;
188
- ```
189
-
190
-
191
-
192
- ## API Reference
174
+ ## πŸ“˜ API Reference
193
175
 
194
176
  ### `createBucket(initial: object, option?: BucketOptions)`
195
177
 
@@ -231,7 +213,21 @@ Creates a new bucket for managing the global state.
231
213
  | `getChanges()` | Returns an array of keys that have changed. |
232
214
  | `clearChanges()` | Resets the change detection for all keys. |
233
215
 
234
- ## License
216
+ ---
217
+
218
+ ## 🀝 Contributing
219
+
220
+ Contributions are welcome! Please check out the [contribution guidelines](https://github.com/devnax/react-state-bucket).
221
+
222
+ ---
223
+
224
+ ## πŸ“„ License
235
225
 
236
226
  This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
237
227
 
228
+ ---
229
+
230
+ ## πŸ“ž Support
231
+
232
+ For help or suggestions, feel free to open an issue on [GitHub](https://github.com/devnax/react-state-bucket/issues) or contact us via [devnaxrul@gmail.com](mailto:devnaxrul@gmail.com).
233
+