@plurid/plurid-functions-react 0.0.0-4 → 0.0.0-6

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.
@@ -0,0 +1,237 @@
1
+ // source/hooks/event/index.ts
2
+ import {
3
+ useEffect
4
+ } from "react";
5
+ var useWindowEvent = (event, callback) => {
6
+ useEffect(() => {
7
+ if (typeof window === "undefined") {
8
+ return;
9
+ }
10
+ window.addEventListener(event, callback, { passive: false });
11
+ return () => {
12
+ if (typeof window === "undefined") {
13
+ return;
14
+ }
15
+ window.removeEventListener(event, callback);
16
+ };
17
+ }, [
18
+ event,
19
+ callback
20
+ ]);
21
+ };
22
+ var useElementEvent = (event, element, callback) => {
23
+ useEffect(() => {
24
+ if (element) {
25
+ element.addEventListener(event, callback, { passive: false });
26
+ }
27
+ return () => element.removeEventListener(event, callback);
28
+ }, [event, callback]);
29
+ };
30
+ var useGlobalKeyDown = (callback, element) => {
31
+ return useElementEvent(
32
+ "keydown",
33
+ element,
34
+ callback
35
+ );
36
+ };
37
+ var useGlobalWheel = (callback, element) => {
38
+ return useElementEvent(
39
+ "wheel",
40
+ element,
41
+ callback
42
+ );
43
+ };
44
+
45
+ // source/hooks/debounce/index.ts
46
+ import {
47
+ useRef,
48
+ useEffect as useEffect2
49
+ } from "react";
50
+ function useDebouncedCallback(callback, wait) {
51
+ const argsRef = useRef();
52
+ const timeout = useRef();
53
+ function cleanup() {
54
+ if (timeout.current) {
55
+ clearTimeout(timeout.current);
56
+ }
57
+ }
58
+ useEffect2(() => cleanup, []);
59
+ return function debouncedCallback(...args) {
60
+ argsRef.current = args;
61
+ cleanup();
62
+ timeout.current = setTimeout(() => {
63
+ if (argsRef.current) {
64
+ callback(...argsRef.current);
65
+ }
66
+ }, wait);
67
+ };
68
+ }
69
+ var debounce_default = useDebouncedCallback;
70
+
71
+ // source/hooks/throttle/index.ts
72
+ import {
73
+ useEffect as useEffect3,
74
+ useRef as useRef2
75
+ } from "react";
76
+ var useThrottledCallback = (callback, delay) => {
77
+ const lastRan = useRef2(Date.now());
78
+ const argsRef = useRef2();
79
+ const timeout = useRef2();
80
+ const cleanup = () => {
81
+ if (timeout.current) {
82
+ clearTimeout(timeout.current);
83
+ }
84
+ };
85
+ useEffect3(() => cleanup, []);
86
+ return (...args) => {
87
+ argsRef.current = args;
88
+ timeout.current = setTimeout(
89
+ () => {
90
+ if (Date.now() - lastRan.current >= delay) {
91
+ if (argsRef.current) {
92
+ callback(...argsRef.current);
93
+ }
94
+ lastRan.current = Date.now();
95
+ }
96
+ },
97
+ delay - (Date.now() - lastRan.current)
98
+ );
99
+ };
100
+ };
101
+ var throttle_default = useThrottledCallback;
102
+
103
+ // source/hooks/portal/index.tsx
104
+ import {
105
+ useRef as useRef3,
106
+ useEffect as useEffect4
107
+ } from "react";
108
+ var createRootElement = (id) => {
109
+ const rootContainer = document.createElement("div");
110
+ rootContainer.setAttribute("id", id);
111
+ return rootContainer;
112
+ };
113
+ var addRootElement = (rootElement, parentID) => {
114
+ const parent = document.getElementById(parentID);
115
+ if (parent) {
116
+ parent.appendChild(rootElement);
117
+ }
118
+ };
119
+ var usePortal = (id, parentID) => {
120
+ const rootElemRef = useRef3(null);
121
+ useEffect4(() => {
122
+ const existingParent = document.querySelector(`#${id}`);
123
+ const parentElem = existingParent || createRootElement(id);
124
+ if (!existingParent) {
125
+ addRootElement(parentElem, parentID);
126
+ }
127
+ if (rootElemRef.current) {
128
+ parentElem.appendChild(rootElemRef.current);
129
+ }
130
+ return () => {
131
+ if (rootElemRef.current) {
132
+ rootElemRef.current.remove();
133
+ }
134
+ if (parentElem.childNodes.length === -1) {
135
+ parentElem.remove();
136
+ }
137
+ };
138
+ }, []);
139
+ const getRootElem = () => {
140
+ if (!rootElemRef.current) {
141
+ rootElemRef.current = document.createElement("div");
142
+ }
143
+ return rootElemRef.current;
144
+ };
145
+ return getRootElem();
146
+ };
147
+ var portal_default = usePortal;
148
+
149
+ // source/hooks/general/index.ts
150
+ import {
151
+ useRef as useRef4,
152
+ useState,
153
+ useEffect as useEffect5
154
+ } from "react";
155
+ var useFalseAfterTimedTrue = (intervalTime = 2e3) => {
156
+ const mounted = useMounted();
157
+ const [
158
+ disabledAfterActivation,
159
+ setDisabledAfterActivation
160
+ ] = useState(false);
161
+ useEffect5(() => {
162
+ let timeout;
163
+ if (disabledAfterActivation) {
164
+ timeout = setTimeout(() => {
165
+ if (!mounted) {
166
+ return;
167
+ }
168
+ setDisabledAfterActivation(false);
169
+ }, intervalTime);
170
+ }
171
+ return () => {
172
+ if (timeout) {
173
+ clearTimeout(timeout);
174
+ timeout = void 0;
175
+ }
176
+ };
177
+ }, [
178
+ disabledAfterActivation
179
+ ]);
180
+ return [
181
+ disabledAfterActivation,
182
+ setDisabledAfterActivation
183
+ ];
184
+ };
185
+ var useMounted = () => {
186
+ const isMounted = useRef4(false);
187
+ useEffect5(() => {
188
+ isMounted.current = true;
189
+ return () => {
190
+ isMounted.current = false;
191
+ };
192
+ }, []);
193
+ return isMounted.current;
194
+ };
195
+
196
+ // source/utilities/createMarkup/index.ts
197
+ var createMarkup = (text) => {
198
+ return {
199
+ __html: text
200
+ };
201
+ };
202
+ var createMarkup_default = createMarkup;
203
+
204
+ // source/utilities/mergeReferences/index.ts
205
+ var mergeReferences = (...refs) => {
206
+ const filteredRefs = refs.filter(Boolean);
207
+ if (!filteredRefs.length) {
208
+ return null;
209
+ }
210
+ if (filteredRefs.length === 1) {
211
+ return filteredRefs[0];
212
+ }
213
+ return (inst) => {
214
+ for (const ref of filteredRefs) {
215
+ if (typeof ref === "function") {
216
+ ref(inst);
217
+ } else if (ref) {
218
+ ref.current = inst;
219
+ }
220
+ }
221
+ };
222
+ };
223
+ var mergeReferences_default = mergeReferences;
224
+ export {
225
+ createMarkup_default as createMarkup,
226
+ mergeReferences_default as mergeReferences,
227
+ debounce_default as useDebouncedCallback,
228
+ useElementEvent,
229
+ useFalseAfterTimedTrue,
230
+ useGlobalKeyDown,
231
+ useGlobalWheel,
232
+ useMounted,
233
+ portal_default as usePortal,
234
+ throttle_default as useThrottledCallback,
235
+ useWindowEvent
236
+ };
237
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../source/hooks/event/index.ts","../source/hooks/debounce/index.ts","../source/hooks/throttle/index.ts","../source/hooks/portal/index.tsx","../source/hooks/general/index.ts","../source/utilities/createMarkup/index.ts","../source/utilities/mergeReferences/index.ts"],"sourcesContent":["// #region imports\nimport {\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nexport const useWindowEvent = (\n event: any,\n callback: any,\n) => {\n useEffect(() => {\n if (typeof window === 'undefined') {\n return;\n }\n window.addEventListener(event, callback, { passive: false });\n\n return () => {\n if (typeof window === 'undefined') {\n return;\n }\n window.removeEventListener(event, callback);\n }\n }, [\n event,\n callback,\n ]);\n};\n\n\nexport const useElementEvent = (\n event: any,\n element: any,\n callback: any,\n) => {\n useEffect(() => {\n if (element) {\n element.addEventListener(event, callback, { passive: false });\n }\n return () => element.removeEventListener(event, callback);\n }, [event, callback]);\n}\n\nexport const useGlobalKeyDown = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('keydown', callback);\n // }\n\n return useElementEvent(\n 'keydown',\n element,\n callback,\n );\n}\n\nexport const useGlobalWheel = (\n callback: any,\n element?: any,\n) => {\n // if (!element) {\n // return useWindowEvent('wheel', callback);\n // }\n\n return useElementEvent(\n 'wheel',\n element,\n callback,\n );\n}\n// #endregion module\n","// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * Source: https://stackoverflow.com/a/57335271\n *\n * @param callback Function to be called.\n * @param wait Debounce time.\n */\nfunction useDebouncedCallback<A extends any[]>(\n callback: (...args: A) => void,\n wait: number,\n) {\n // track args & timeout handle between calls\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n function cleanup() {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n // make sure our timeout gets cleared if\n // our consuming component gets unmounted\n useEffect(() => cleanup, []);\n\n return function debouncedCallback(\n ...args: A\n ) {\n // capture latest args\n argsRef.current = args;\n\n // clear debounce timer\n cleanup();\n\n // start waiting again\n timeout.current = setTimeout(() => {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n }, wait);\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useDebouncedCallback;\n// #endregion exports\n","// #region imports\nimport {\n useEffect,\n useRef,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\n/**\n * @param callback\n * @param delay\n */\nconst useThrottledCallback = <A extends any[]>(\n callback: (...args: A) => void,\n delay: number,\n) => {\n // track args & timeout handle between calls\n const lastRan = useRef(Date.now());\n const argsRef = useRef<A>();\n const timeout = useRef<ReturnType<typeof setTimeout>>();\n\n const cleanup = () => {\n if(timeout.current) {\n clearTimeout(timeout.current);\n }\n }\n\n useEffect(() => cleanup, []);\n\n return (\n ...args: A\n ) => {\n argsRef.current = args;\n\n timeout.current = setTimeout(\n () => {\n if (Date.now() - lastRan.current >= delay) {\n if(argsRef.current) {\n callback(...argsRef.current);\n }\n lastRan.current = Date.now();\n }\n },\n delay - (Date.now() - lastRan.current)\n );\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default useThrottledCallback;\n// #endregion exports\n","/**\n * Based on\n * https://www.jayfreestone.com/writing/react-portals-with-hooks/\n *\n */\n\n\n// #region imports\nimport {\n useRef,\n useEffect,\n} from 'react';\n// #endregion imports\n\n\n\n// #region module\nconst createRootElement = (\n id: string,\n): Element => {\n const rootContainer = document.createElement('div');\n rootContainer.setAttribute('id', id);\n return rootContainer;\n}\n\n\n/**\n * Appends element as last child of body.\n *\n * @param rootElement\n */\nconst addRootElement = (\n rootElement: Element,\n parentID: string,\n) => {\n const parent = document.getElementById(parentID);\n\n if (parent) {\n parent.appendChild(rootElement);\n }\n}\n\n\n/**\n * Hook to create a React Portal.\n * Automatically handles creating and tearing-down the root elements (no SRR\n * makes this trivial), so there is no need to ensure the parent target already\n * exists.\n * @example\n * const target = usePortal(id, [id]);\n * return createPortal(children, target);\n *\n * @param id The id of the target container, e.g 'modal' or 'spotlight'\n * @returns The DOM node to use as the Portal target.\n */\nconst usePortal = (\n id: string,\n parentID: string,\n): any => {\n const rootElemRef = useRef<Element | null>(null);\n\n useEffect(() => {\n // Look for existing target dom element to append to\n const existingParent = document.querySelector(`#${id}`);\n // Parent is either a new root or the existing dom element\n const parentElem = existingParent || createRootElement(id);\n\n // If there is no existing DOM element, add a new one.\n if (!existingParent) {\n addRootElement(parentElem, parentID);\n }\n\n // Add the detached element to the parent\n if (rootElemRef.current) {\n parentElem.appendChild(rootElemRef.current);\n }\n\n return () => {\n if (rootElemRef.current) {\n rootElemRef.current.remove();\n }\n\n if (parentElem.childNodes.length === -1) {\n parentElem.remove();\n }\n };\n }, []);\n\n /**\n * It's important we evaluate this lazily:\n * - We need first render to contain the DOM element, so it shouldn't happen\n * in useEffect. We would normally put this in the constructor().\n * - We can't do 'const rootElemRef = useRef(document.createElement('div))',\n * since this will run every single render (that's a lot).\n * - We want the ref to consistently point to the same DOM element and only\n * ever run once.\n * @link https://reactjs.org/docs/hooks-faq.html#how-to-create-expensive-objects-lazily\n */\n const getRootElem = () => {\n if (!rootElemRef.current) {\n rootElemRef.current = document.createElement('div');\n }\n return rootElemRef.current;\n }\n\n return getRootElem();\n}\n// #endregion module\n\n\n\n// #region exports\nexport default usePortal;\n// #endregion exports\n","// #region imports\n // #region libraries\n import React, {\n useRef,\n useState,\n useEffect,\n } from 'react';\n // #endregion libraries\n// #region imports\n\n\n\n// #region module\n/**\n * After a `true` dispatch, it will wait the `intervalTime` and autoset to `false`.\n *\n * @param intervalTime\n * @returns\n */\nconst useFalseAfterTimedTrue = (\n intervalTime = 2_000, // ms\n): [boolean, React.Dispatch<React.SetStateAction<boolean>>] => {\n // #region references\n const mounted = useMounted();\n // #endregion references\n\n // #region state\n const [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ] = useState(false);\n // #endregion state\n\n // #region effects\n useEffect(() => {\n // `ReturnType<typeof setTimeout>` (universal) instead of the Node-only `NodeJS.Timeout` — works in\n // both the browser (number) and Node without depending on @types/node being resolvable.\n let timeout: ReturnType<typeof setTimeout> | undefined;\n\n if (disabledAfterActivation) {\n timeout = setTimeout(() => {\n if (!mounted) {\n return;\n }\n\n setDisabledAfterActivation(false);\n }, intervalTime);\n }\n\n return () => {\n if (timeout) {\n clearTimeout(timeout);\n timeout = undefined;\n }\n }\n }, [\n disabledAfterActivation,\n ]);\n // #endregion effects\n\n // #region return\n return [\n disabledAfterActivation,\n setDisabledAfterActivation,\n ];\n // #endregion return\n}\n\n\n/**\n * Keeps reference of the current mounted component.\n *\n * @returns\n */\nconst useMounted = () => {\n // #region references\n const isMounted = useRef(false);\n // #endregion references\n\n // #region effects\n useEffect(() => {\n isMounted.current = true;\n\n return () => {\n isMounted.current = false;\n }\n }, []);\n // #endregion effects\n\n // #region return\n return isMounted.current;\n // #endregion return\n}\n// #endregion module\n\n\n\n// #region exports\nexport {\n useFalseAfterTimedTrue,\n useMounted,\n};\n// #endregion exports\n","// #region module\nconst createMarkup = (\n text: string,\n) => {\n return {\n __html: text,\n };\n}\n// #endregion module\n\n\n\n// #region exports\nexport default createMarkup;\n// #endregion exports\n","// #region module\n/**\n * Merges multiple references into one `ref` attribute.\n *\n * ``` jsx\n * <SomeComponent\n * ref={merge(ref1, ref2)}\n * />\n * ```\n *\n * Source: https://www.davedrinks.coffee/how-do-i-use-two-react-refs/\n *\n * @param refs\n */\nconst mergeReferences = (\n ...refs: any[]\n) => {\n const filteredRefs = refs.filter(Boolean);\n\n if (!filteredRefs.length) {\n return null;\n }\n\n if (filteredRefs.length === 1) {\n return filteredRefs[0];\n }\n\n return (inst: any) => {\n for (const ref of filteredRefs) {\n if (typeof ref === 'function') {\n ref(inst);\n } else if (ref) {\n ref.current = inst;\n }\n }\n };\n};\n// #endregion module\n\n\n\n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AM;AACT,gBAAU,UAAU;AAAA,IACxB;AAAA,EACJ,GAAG,CAAC,CAAC;AAIL,SAAO,UAAU;AAErB;;;AC3FA,IAAM,eAAe,CACjB,SACC;AACD,SAAO;AAAA,IACH,QAAQ;AAAA,EACZ;AACJ;AAMA,IAAO,uBAAQ;;;ACCf,IAAM,kBAAkB,IACjB,SACF;AACD,QAAM,eAAe,KAAK,OAAO,OAAO;AAExC,MAAI,CAAC,aAAa,QAAQ;AACtB,WAAO;AAAA,EACX;AAEA,MAAI,aAAa,WAAW,GAAG;AAC3B,WAAO,aAAa,CAAC;AAAA,EACzB;AAEA,SAAO,CAAC,SAAc;AAClB,eAAW,OAAO,cAAc;AAC5B,UAAI,OAAO,QAAQ,YAAY;AAC3B,YAAI,IAAI;AAAA,MACZ,WAAW,KAAK;AACZ,YAAI,UAAU;AAAA,MAClB;AAAA,IACJ;AAAA,EACJ;AACJ;AAMA,IAAO,0BAAQ;","names":["useEffect","useEffect","useRef","useRef","useEffect","useRef","useEffect"]}
package/package.json CHANGED
@@ -1,66 +1,66 @@
1
1
  {
2
- "name": "@plurid/plurid-functions-react",
3
- "version": "0.0.0-4",
4
- "description": "General Utility Functions for Plurid React Applications",
5
- "keywords": [
6
- "plurid",
7
- "functions",
8
- "react"
9
- ],
10
- "author": "ly3xqhl8g9 <ly3xqhl8g9@plurid.com> (https://plurid.com)",
11
- "license": "SEE LICENSE IN LICENSE",
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/plurid/plurid-functions-typescript"
15
- },
16
- "bugs": {
17
- "email": "source@plurid.com",
18
- "url": "https://github.com/plurid/plurid-functions-typescript/issues"
19
- },
20
- "homepage": "https://github.com/plurid/plurid-functions-typescript",
21
- "publishConfig": {
22
- "registry": "https://registry.npmjs.org/",
23
- "access": "public"
24
- },
25
- "files": [
26
- "distribution/"
27
- ],
28
- "main": "distribution/index.js",
29
- "module": "distribution/index.es.js",
30
- "types": "distribution/index.d.js",
31
- "engines": {
32
- "node": ">=12",
33
- "npm": ">=6"
34
- },
35
- "scripts": {
36
- "test": "jest -c ./configurations/jest.config.js ./source",
37
- "test.suite": "jest -c ./configurations/jest.config.js",
38
- "clean": "rm -rf ./distribution",
39
- "watch": "yarn clean && rollup -c ./scripts/rollup.config.js -w",
40
- "build.clean": "find ./distribution -type d -name '*__tests__' -exec rm -rf {} + && find ./distribution -type f -name '*.DS_Store' -exec rm -rf {} +",
41
- "build.production": "rollup -c ./scripts/rollup.config.js",
42
- "build": "yarn clean && yarn build.production && yarn build.clean",
43
- "prepublishOnly": "yarn build"
44
- },
45
- "peerDependencies": {
46
- "react": ">=17"
47
- },
48
- "devDependencies": {
49
- "@types/crypto-js": "^4.0.2",
50
- "@types/jest": "^27.0.2",
51
- "@types/node": "^16.9.6",
52
- "@types/react": "^17.0.24",
53
- "@typescript-eslint/eslint-plugin": "^4.31.2",
54
- "@typescript-eslint/parser": "^4.31.2",
55
- "@zerollup/ts-transform-paths": "^1.7.18",
56
- "eslint": "^7.32.0",
57
- "jest": "^27.2.1",
58
- "react": "^17.0.2",
59
- "rollup": "^2.57.0",
60
- "rollup-plugin-typescript2": "^0.30.0",
61
- "ts-jest": "^27.0.5",
62
- "ts-node": "^10.2.1",
63
- "ttypescript": "^1.5.12",
64
- "typescript": "^4.4.3"
2
+ "name": "@plurid/plurid-functions-react",
3
+ "version": "0.0.0-6",
4
+ "sideEffects": false,
5
+ "description": "General Utility Functions for Plurid React Applications",
6
+ "keywords": [
7
+ "plurid",
8
+ "functions",
9
+ "react"
10
+ ],
11
+ "author": "ly3xqhl8g9 <ly3xqhl8g9@plurid.com> (https://plurid.com)",
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/plurid/plurid-functions-typescript"
16
+ },
17
+ "bugs": {
18
+ "email": "source@plurid.com",
19
+ "url": "https://github.com/plurid/plurid-functions-typescript/issues"
20
+ },
21
+ "homepage": "https://github.com/plurid/plurid-functions-typescript",
22
+ "publishConfig": {
23
+ "registry": "https://registry.npmjs.org/",
24
+ "access": "public"
25
+ },
26
+ "files": [
27
+ "distribution/"
28
+ ],
29
+ "main": "distribution/index.js",
30
+ "module": "distribution/index.mjs",
31
+ "types": "distribution/index.d.ts",
32
+ "engines": {
33
+ "node": ">=18",
34
+ "npm": ">=8"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=19"
38
+ },
39
+ "devDependencies": {
40
+ "@types/crypto-js": "^4.1.1",
41
+ "@types/jest": "^30.0.0",
42
+ "@types/node": "^18.16.1",
43
+ "@types/react": "^19.2.0",
44
+ "jest": "^30.4.2",
45
+ "react": "^19.2.0",
46
+ "ts-jest": "^29.4.11",
47
+ "ts-node": "^10.9.1",
48
+ "typescript": "^6.0.3",
49
+ "tsup": "^8.5.1"
50
+ },
51
+ "exports": {
52
+ ".": {
53
+ "types": "./distribution/index.d.ts",
54
+ "import": "./distribution/index.mjs",
55
+ "require": "./distribution/index.js"
65
56
  }
66
- }
57
+ },
58
+ "scripts": {
59
+ "test": "jest -c ./configurations/jest.config.js ./source",
60
+ "test.suite": "jest -c ./configurations/jest.config.js",
61
+ "clean": "rm -rf ./distribution",
62
+ "build.production": "tsup",
63
+ "build": "tsup",
64
+ "build.development": "tsup --watch"
65
+ }
66
+ }
@@ -1,8 +0,0 @@
1
- /**
2
- * Source: https://stackoverflow.com/a/57335271
3
- *
4
- * @param callback Function to be called.
5
- * @param wait Debounce time.
6
- */
7
- declare function useDebouncedCallback<A extends any[]>(callback: (...args: A) => void, wait: number): (...args: A) => void;
8
- export default useDebouncedCallback;
@@ -1,4 +0,0 @@
1
- export declare const useWindowEvent: (event: any, callback: any) => void;
2
- export declare const useElementEvent: (event: any, element: any, callback: any) => void;
3
- export declare const useGlobalKeyDown: (callback: any, element?: any) => void;
4
- export declare const useGlobalWheel: (callback: any, element?: any) => void;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- /**
3
- * After a `true` dispatch, it will wait the `intervalTime` and autoset to `false`.
4
- *
5
- * @param intervalTime
6
- * @returns
7
- */
8
- declare const useFalseAfterTimedTrue: (intervalTime?: number) => [boolean, React.Dispatch<React.SetStateAction<boolean>>];
9
- /**
10
- * Keeps reference of the current mounted component.
11
- *
12
- * @returns
13
- */
14
- declare const useMounted: () => boolean;
15
- export { useFalseAfterTimedTrue, useMounted, };
@@ -1,6 +0,0 @@
1
- import { useWindowEvent, useGlobalKeyDown, useGlobalWheel, useElementEvent } from './event';
2
- import useDebouncedCallback from './debounce';
3
- import useThrottledCallback from './throttle';
4
- import usePortal from './portal';
5
- export * from './general';
6
- export { useWindowEvent, useGlobalKeyDown, useGlobalWheel, useElementEvent, useDebouncedCallback, useThrottledCallback, usePortal, };
@@ -1,19 +0,0 @@
1
- /**
2
- * Based on
3
- * https://www.jayfreestone.com/writing/react-portals-with-hooks/
4
- *
5
- */
6
- /**
7
- * Hook to create a React Portal.
8
- * Automatically handles creating and tearing-down the root elements (no SRR
9
- * makes this trivial), so there is no need to ensure the parent target already
10
- * exists.
11
- * @example
12
- * const target = usePortal(id, [id]);
13
- * return createPortal(children, target);
14
- *
15
- * @param id The id of the target container, e.g 'modal' or 'spotlight'
16
- * @returns The DOM node to use as the Portal target.
17
- */
18
- declare const usePortal: (id: string, parentID: string) => any;
19
- export default usePortal;
@@ -1,6 +0,0 @@
1
- /**
2
- * @param callback
3
- * @param delay
4
- */
5
- declare const useThrottledCallback: <A extends any[]>(callback: (...args: A) => void, delay: number) => (...args: A) => void;
6
- export default useThrottledCallback;