react-hooks-global-states 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.
- package/README.md +13 -7
- package/lib/src/GlobalStore.d.ts +5 -5
- package/lib/src/GlobalStore.types.d.ts +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
# react-hooks-global-states
|
|
1
|
+
# react-hooks-global-states 🌟
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Hi There! Welcome to **react-hooks-global-states** your New State Management Solution for React Components 🚀
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Are you looking for a solution to manage **global state** in your **React components**? Look no further!
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
**react-hooks-global-states** is your option for efficiently handling global state management in your React applications.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
One line of code for a **global state**! try it out now on [CODEPEN-react-global-state-hooks](https://codepen.io/johnnynabetes/pen/WNmeGwb?editors=0010) and witness the magic ✨.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
For a deeper dive into how these hooks work, check out a comprehensive example at [react-global-state-hooks-example](https://johnny-quesada-developer.github.io/react-global-state-hooks-example/) 📘.
|
|
14
|
+
|
|
15
|
+
Want to explore how it works with **React Native**? Head over to [react-native-global-state-hooks](https://www.npmjs.com/package/react-native-global-state-hooks) for a hands-on experience 📱. You can also explore a **TODO-LIST** example using global state and asynchronous storage by heading to [todo-list-with-global-hooks](https://github.com/johnny-quesada-developer/todo-list-with-global-hooks.git) 📝.
|
|
16
|
+
|
|
17
|
+
For a more visual introduction, watch our informative video [here!](https://www.youtube.com/watch?v=1UBqXk2MH8I) 🎥 and dive into the code on [global-hooks-example](https://github.com/johnny-quesada-developer/global-hooks-example) 🧩.
|
|
18
|
+
|
|
19
|
+
The best part? **react-hooks-global-states** is compatible with both **React** and **React Native**. If you're building web applications, explore [**react-global-state-hooks**](https://www.npmjs.com/package/react-global-state-hooks), and for your React Native projects, check out [**react-native-global-state-hooks**](https://www.npmjs.com/package/react-native-global-state-hooks). These specialized libraries extend the capabilities of **react-hooks-global-states** to perfectly fit your specific development environments. Discover the ease of global state management today! 🌐
|
|
14
20
|
|
|
15
21
|
# Creating a global state
|
|
16
22
|
|
package/lib/src/GlobalStore.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, MetadataGetter } from
|
|
1
|
+
import { ActionCollectionConfig, StateSetter, GlobalStoreConfig, ActionCollectionResult, StateConfigCallbackParam, MetadataSetter, UseHookConfig, StateGetter, SubscribeCallbackConfig, SubscribeCallback, SelectorCallback, SubscriberParameters, SubscriptionCallback, MetadataGetter } from './GlobalStore.types';
|
|
2
2
|
export declare const throwNoSubscribersWereAdded: () => never;
|
|
3
3
|
/**
|
|
4
4
|
* The GlobalStore class is the main class of the library and it is used to create a GlobalStore instances
|
|
@@ -40,7 +40,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
|
|
|
40
40
|
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
41
41
|
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
42
42
|
* */
|
|
43
|
-
protected onInit?: GlobalStoreConfig<TState, TMetadata, TStateSetter>[
|
|
43
|
+
protected onInit?: GlobalStoreConfig<TState, TMetadata, TStateSetter>['onInit'];
|
|
44
44
|
/**
|
|
45
45
|
* execute every time the state is changed
|
|
46
46
|
* @template {TState} TState - The type of the state object
|
|
@@ -52,7 +52,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
|
|
|
52
52
|
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
53
53
|
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
54
54
|
* */
|
|
55
|
-
protected onStateChanged?: GlobalStoreConfig<TState, TMetadata, TStateSetter>[
|
|
55
|
+
protected onStateChanged?: GlobalStoreConfig<TState, TMetadata, TStateSetter>['onStateChanged'];
|
|
56
56
|
/**
|
|
57
57
|
* Execute each time a new component gets subscribed to the store
|
|
58
58
|
* @template {TState} TState - The type of the state object
|
|
@@ -64,7 +64,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
|
|
|
64
64
|
* @param {Dispatch<SetStateAction<TMetadata>>} parameters.setMetadata - The setMetadata function to update the metadata
|
|
65
65
|
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
66
66
|
* */
|
|
67
|
-
protected onSubscribed?: GlobalStoreConfig<TState, TMetadata, TStateSetter>[
|
|
67
|
+
protected onSubscribed?: GlobalStoreConfig<TState, TMetadata, TStateSetter>['onSubscribed'];
|
|
68
68
|
/**
|
|
69
69
|
* Execute every time a state change is triggered and before the state is updated, it allows to prevent the state change by returning true
|
|
70
70
|
* @template {TState} TState - The type of the state object
|
|
@@ -77,7 +77,7 @@ export declare class GlobalStore<TState, TMetadata = null, TStateSetter extends
|
|
|
77
77
|
* @param {() => TMetadata} parameters.getMetadata - The getMetadata function to get the metadata
|
|
78
78
|
* @returns {boolean} - true to prevent the state change, false to allow the state change
|
|
79
79
|
* */
|
|
80
|
-
protected computePreventStateChange?: GlobalStoreConfig<TState, TMetadata, TStateSetter>[
|
|
80
|
+
protected computePreventStateChange?: GlobalStoreConfig<TState, TMetadata, TStateSetter>['computePreventStateChange'];
|
|
81
81
|
/**
|
|
82
82
|
* We use a wrapper in order to be able to force the state update when necessary even with primitive types
|
|
83
83
|
*/
|
|
@@ -148,7 +148,7 @@ export type ActionCollectionResult<TState, TMetadata, TStateSetter extends Actio
|
|
|
148
148
|
* @template {TStateSetter} TStateSetter - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
|
|
149
149
|
* @template {ActionCollectionResult<TState, TStateSetter>} TStateSetter - the result of the API (optional) - if you don't pass an API as a parameter, you can pass null
|
|
150
150
|
* */
|
|
151
|
-
export type StateConfigCallbackParam<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
|
|
151
|
+
export type StateConfigCallbackParam<TState = any, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = {
|
|
152
152
|
actions: ActionCollectionResult<TState, TMetadata, TStateSetter>;
|
|
153
153
|
} & StoreTools<TState, TMetadata>;
|
|
154
154
|
/**
|
|
@@ -157,7 +157,7 @@ export type StateConfigCallbackParam<TState, TMetadata, TStateSetter extends Act
|
|
|
157
157
|
* @template {TMetadata} TMetadata - The metadata type
|
|
158
158
|
* @template {TStateSetter} TStateSetter - The storeActionsConfig type (optional) - if you pass an storeActionsConfig the hook will return an object with the actions
|
|
159
159
|
*/
|
|
160
|
-
export type StateChangesParam<TState, TMetadata, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = StateConfigCallbackParam<TState, TMetadata, TStateSetter> & StateChanges<TState>;
|
|
160
|
+
export type StateChangesParam<TState = any, TMetadata = null, TStateSetter extends ActionCollectionConfig<TState, TMetadata> | StateSetter<TState> = StateSetter<TState>> = StateConfigCallbackParam<TState, TMetadata, TStateSetter> & StateChanges<TState>;
|
|
161
161
|
/**
|
|
162
162
|
* Configuration of the store (optional) - if you don't need to use the store configuration you don't need to pass this parameter
|
|
163
163
|
* @param {StateConfigCallbackParam<TState, TMetadata> => void} onInit - callback function called when the store is initialized
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-hooks-global-states",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "This is a package to easily handling global-state across your react-components No-redux",
|
|
5
5
|
"main": "lib/bundle.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
@@ -66,9 +66,9 @@
|
|
|
66
66
|
"react": ">=17.0.0",
|
|
67
67
|
"react-test-renderer": "^17.0.1",
|
|
68
68
|
"ts-jest": "^26.4.4",
|
|
69
|
-
"ts-loader": "^9.
|
|
70
|
-
"tslib": "^2.
|
|
71
|
-
"typescript": "^
|
|
69
|
+
"ts-loader": "^9.5.1",
|
|
70
|
+
"tslib": "^2.6.2",
|
|
71
|
+
"typescript": "^5.3.3",
|
|
72
72
|
"webpack": "^5.76.3",
|
|
73
73
|
"webpack-cli": "^5.0.1"
|
|
74
74
|
},
|