@w3ux/hooks 0.0.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.
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@w3ux/hooks",
3
+ "version": "0.0.1",
4
+ "license": "GPL-3.0-only",
5
+ "type": "module"
6
+ }
@@ -0,0 +1 @@
1
+ export declare const useEffectIgnoreInitial: <T, U>(fn: T, deps: U[]) => void;
@@ -0,0 +1,23 @@
1
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
+ if (ar || !(i in from)) {
4
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
+ ar[i] = from[i];
6
+ }
7
+ }
8
+ return to.concat(ar || Array.prototype.slice.call(from));
9
+ };
10
+ import { useEffect, useRef } from "react";
11
+ export var useEffectIgnoreInitial = function (fn, deps) {
12
+ var isInitial = useRef(true);
13
+ useEffect(function () {
14
+ if (!isInitial.current) {
15
+ if (typeof fn === "function") {
16
+ fn();
17
+ }
18
+ }
19
+ isInitial.current = false;
20
+ }, deps ? __spreadArray([], deps, true) : undefined);
21
+ };
22
+
23
+
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useEffectIgnoreInitial.tsx"],"names":[],"mappings":"AAAA;wCACwC;;;;;;;;;;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,CAAC,IAAM,sBAAsB,GAAG,UAAO,EAAK,EAAE,IAAS;IAC3D,IAAM,SAAS,GAAG,MAAM,CAAU,IAAI,CAAC,CAAC;IACxC,SAAS,CACP;QACE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;YACvB,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC7B,EAAE,EAAE,CAAC;YACP,CAAC;QACH,CAAC;QACD,SAAS,CAAC,OAAO,GAAG,KAAK,CAAC;IAC5B,CAAC,EACD,IAAI,CAAC,CAAC,mBAAK,IAAI,QAAE,CAAC,CAAC,SAAS,CAC7B,CAAC;AACJ,CAAC,CAAC","file":"useEffectIgnoreInitial.js","sourcesContent":["/* @license Copyright 2024 @polkadot-cloud/library authors & contributors\nSPDX-License-Identifier: GPL-3.0-only */\n\nimport { useEffect, useRef } from \"react\";\n\nexport const useEffectIgnoreInitial = <T, U>(fn: T, deps: U[]) => {\n const isInitial = useRef<boolean>(true);\n useEffect(\n () => {\n if (!isInitial.current) {\n if (typeof fn === \"function\") {\n fn();\n }\n }\n isInitial.current = false;\n },\n deps ? [...deps] : undefined\n );\n};\n"]}