@siberiacancode/reactuse 0.1.1 → 0.2.0
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/dist/cjs/helpers/createContext/createContext.cjs +2 -0
- package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -0
- package/dist/cjs/helpers/createStore/createStore.cjs +2 -0
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -0
- package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
- package/dist/cjs/hooks/useField/useField.cjs +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createContext/createContext.mjs +38 -0
- package/dist/esm/helpers/createContext/createContext.mjs.map +1 -0
- package/dist/esm/helpers/createStore/createStore.mjs +32 -0
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -0
- package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs +1 -3
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useGamepad/useGamepad.mjs +7 -2
- package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs +14 -10
- package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
- package/dist/esm/index.mjs +323 -319
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/helpers/createContext/createContext.d.ts +48 -0
- package/dist/types/helpers/createStore/createStore.d.ts +31 -0
- package/dist/types/helpers/index.d.ts +2 -0
- package/dist/types/hooks/useClipboard/useClipboard.d.ts +1 -1
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +6 -6
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JSX, ReactNode } from 'react';
|
|
2
|
+
/** The create context options type */
|
|
3
|
+
export interface CreateContextOptions {
|
|
4
|
+
/** Display name for the context (useful for debugging) */
|
|
5
|
+
name?: string;
|
|
6
|
+
/** Whether to throw an error if context is used outside of Provider */
|
|
7
|
+
strict?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** The context value type */
|
|
10
|
+
export interface ContextValue<Value> {
|
|
11
|
+
/** The context value */
|
|
12
|
+
value: Value | undefined;
|
|
13
|
+
/** The context set function */
|
|
14
|
+
set: (value: Value) => void;
|
|
15
|
+
}
|
|
16
|
+
/** The provider props type */
|
|
17
|
+
export interface ProviderProps<Value> {
|
|
18
|
+
/** The children */
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
/** The initial value */
|
|
21
|
+
initialValue?: Value;
|
|
22
|
+
}
|
|
23
|
+
/** The create context return type */
|
|
24
|
+
export interface CreateContextReturn<Value> {
|
|
25
|
+
/** The context instance */
|
|
26
|
+
instance: React.Context<ContextValue<Value>>;
|
|
27
|
+
/** The provider component */
|
|
28
|
+
Provider: (props: ProviderProps<Value>) => JSX.Element;
|
|
29
|
+
/** The selector hook */
|
|
30
|
+
useSelect: {
|
|
31
|
+
<Selected>(selector: (value: Value) => Selected): Selected;
|
|
32
|
+
(): ContextValue<Value>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @name createContext
|
|
37
|
+
* @description - Creates a typed context with additional utilities
|
|
38
|
+
* @category Helpers
|
|
39
|
+
*
|
|
40
|
+
* @template Value - The type of value that will be stored in the context
|
|
41
|
+
* @param {Value | undefined} [defaultValue] - Default value for the context
|
|
42
|
+
* @param {CreateContextOptions<Value>} [options] - Additional options for context creation
|
|
43
|
+
* @returns {CreateContextReturn<Value>} Object containing context utilities and components
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const { useSelect, instance, Provider } = createContext<number>(0);
|
|
47
|
+
*/
|
|
48
|
+
export declare const createContext: <Value>(defaultValue?: Value | undefined, options?: CreateContextOptions) => CreateContextReturn<Value>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type SetStateAction<Value> = ((prev: Value) => Value) | Value;
|
|
2
|
+
type StateCreator<Value> = (set: (action: SetStateAction<Value>) => void, get: () => Value) => Value;
|
|
3
|
+
export interface StoreApi<Value> {
|
|
4
|
+
getInitialState: () => Value;
|
|
5
|
+
getState: () => Value;
|
|
6
|
+
setState: (action: SetStateAction<Value>) => void;
|
|
7
|
+
subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @name createStore
|
|
11
|
+
* @description - Creates a store with state management capabilities
|
|
12
|
+
* @category Helpers
|
|
13
|
+
*
|
|
14
|
+
* @template Value - The type of the store state
|
|
15
|
+
*
|
|
16
|
+
* @param {StateCreator<Value>} createState - Function that initializes the store state
|
|
17
|
+
* @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { set, get, use, subscribe } = createStore((set) => ({
|
|
21
|
+
* count: 0,
|
|
22
|
+
* increment: () => set(state => ({ count: state.count + 1 }))
|
|
23
|
+
* }));
|
|
24
|
+
*/
|
|
25
|
+
export declare function createStore<Value>(createState: StateCreator<Value> | Value): {
|
|
26
|
+
set: (action: SetStateAction<Value>) => void;
|
|
27
|
+
get: () => Value;
|
|
28
|
+
use: <Selected>(selector: (state: Value) => Selected) => Selected;
|
|
29
|
+
subscribe: (listener: (state: Value, prevState: Value) => void) => () => boolean;
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -21,6 +21,6 @@ export interface UseCopyToClipboardParams {
|
|
|
21
21
|
* @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
-
* const {
|
|
24
|
+
* const { value, copy } = useClipboard();
|
|
25
25
|
*/
|
|
26
26
|
export declare const useClipboard: (params?: UseCopyToClipboardParams) => UseCopyToClipboardReturn;
|
|
@@ -29,7 +29,7 @@ export interface UseIntersectionObserver {
|
|
|
29
29
|
* @param {boolean} [options.enabled=true] The IntersectionObserver options
|
|
30
30
|
* @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
|
|
31
31
|
* @param {HookTarget} [options.root] The root element to observe
|
|
32
|
-
* @returns {UseIntersectionObserverReturn} An object containing the state
|
|
32
|
+
* @returns {UseIntersectionObserverReturn} An object containing the state
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
* const { ref, entry, inView } = useIntersectionObserver();
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "The ultimate collection of react hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -68,17 +68,17 @@
|
|
|
68
68
|
"@testing-library/dom": "^10.4.0",
|
|
69
69
|
"@testing-library/react": "^16.3.0",
|
|
70
70
|
"@types/dom-speech-recognition": "^0.0.6",
|
|
71
|
-
"@types/react": "^19.1.
|
|
72
|
-
"@types/react-dom": "^19.1.
|
|
71
|
+
"@types/react": "^19.1.3",
|
|
72
|
+
"@types/react-dom": "^19.1.3",
|
|
73
73
|
"@types/web-bluetooth": "^0.0.21",
|
|
74
74
|
"@vitejs/plugin-react": "^4.4.1",
|
|
75
|
-
"core-js": "^3.
|
|
75
|
+
"core-js": "^3.42.0",
|
|
76
76
|
"react": "^19.1.0",
|
|
77
77
|
"react-dom": "^19.1.0",
|
|
78
78
|
"shx": "^0.4.0",
|
|
79
|
-
"vite": "^6.3.
|
|
79
|
+
"vite": "^6.3.5",
|
|
80
80
|
"vite-plugin-dts": "^4.5.3",
|
|
81
|
-
"vitest": "^3.1.
|
|
81
|
+
"vitest": "^3.1.3"
|
|
82
82
|
},
|
|
83
83
|
"lint-staged": {
|
|
84
84
|
"*.{js,ts,tsx}": [
|