@hanzogui/use-previous 2.0.0-rc.41-hanzoai.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/LICENSE +21 -0
- package/dist/cjs/index.cjs +52 -0
- package/dist/cjs/index.native.js +55 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +16 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +16 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +18 -0
- package/types/index.d.ts +3 -0
- package/types/index.d.ts.map +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var index_exports = {};
|
|
35
|
+
__export(index_exports, {
|
|
36
|
+
usePrevious: () => usePrevious
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
function usePrevious(value) {
|
|
41
|
+
const ref = React.useRef({
|
|
42
|
+
value,
|
|
43
|
+
previous: value
|
|
44
|
+
});
|
|
45
|
+
return React.useMemo(() => {
|
|
46
|
+
if (ref.current.value !== value) {
|
|
47
|
+
ref.current.previous = ref.current.value;
|
|
48
|
+
ref.current.value = value;
|
|
49
|
+
}
|
|
50
|
+
return ref.current.previous;
|
|
51
|
+
}, [value]);
|
|
52
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
36
|
+
var index_exports = {};
|
|
37
|
+
__export(index_exports, {
|
|
38
|
+
usePrevious: () => usePrevious
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(index_exports);
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
function usePrevious(value) {
|
|
43
|
+
var ref = React.useRef({
|
|
44
|
+
value,
|
|
45
|
+
previous: value
|
|
46
|
+
});
|
|
47
|
+
return React.useMemo(function () {
|
|
48
|
+
if (ref.current.value !== value) {
|
|
49
|
+
ref.current.previous = ref.current.value;
|
|
50
|
+
ref.current.value = value;
|
|
51
|
+
}
|
|
52
|
+
return ref.current.previous;
|
|
53
|
+
}, [value]);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__create","Object","create","__defProp","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__getProtoOf","getPrototypeOf","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toESM","mod","isNodeMode","__esModule","value","__toCommonJS","index_exports","usePrevious","module","exports","React","require","ref","useRef","previous","useMemo","current"],"sources":["index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\n__export(index_exports, {\n usePrevious: () => usePrevious\n});\nmodule.exports = __toCommonJS(index_exports);\nvar React = __toESM(require(\"react\"), 1);\nfunction usePrevious(value) {\n var ref = React.useRef({\n value,\n previous: value\n });\n return React.useMemo(function() {\n if (ref.current.value !== value) {\n ref.current.previous = ref.current.value;\n ref.current.value = value;\n }\n return ref.current.previous;\n }, [\n value\n ]);\n}\n//# sourceMappingURL=index.js.map\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function usePrevious(value) {
|
|
3
|
+
const ref = React.useRef({
|
|
4
|
+
value,
|
|
5
|
+
previous: value
|
|
6
|
+
});
|
|
7
|
+
return React.useMemo(() => {
|
|
8
|
+
if (ref.current.value !== value) {
|
|
9
|
+
ref.current.previous = ref.current.value;
|
|
10
|
+
ref.current.value = value;
|
|
11
|
+
}
|
|
12
|
+
return ref.current.previous;
|
|
13
|
+
}, [value]);
|
|
14
|
+
}
|
|
15
|
+
export { usePrevious };
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","usePrevious","value","ref","useRef","previous","useMemo","current"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAEhB,SAASC,YAAeC,KAAA,EAAa;EAC1C,MAAMC,GAAA,GAAMH,KAAA,CAAMI,MAAA,CAAO;IAAEF,KAAA;IAAOG,QAAA,EAAUH;EAAM,CAAC;EAKnD,OAAOF,KAAA,CAAMM,OAAA,CAAQ,MAAM;IACzB,IAAIH,GAAA,CAAII,OAAA,CAAQL,KAAA,KAAUA,KAAA,EAAO;MAC/BC,GAAA,CAAII,OAAA,CAAQF,QAAA,GAAWF,GAAA,CAAII,OAAA,CAAQL,KAAA;MACnCC,GAAA,CAAII,OAAA,CAAQL,KAAA,GAAQA,KAAA;IACtB;IACA,OAAOC,GAAA,CAAII,OAAA,CAAQF,QAAA;EACrB,GAAG,CAACH,KAAK,CAAC;AACZ","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function usePrevious(value) {
|
|
3
|
+
const ref = React.useRef({
|
|
4
|
+
value,
|
|
5
|
+
previous: value
|
|
6
|
+
});
|
|
7
|
+
return React.useMemo(() => {
|
|
8
|
+
if (ref.current.value !== value) {
|
|
9
|
+
ref.current.previous = ref.current.value;
|
|
10
|
+
ref.current.value = value;
|
|
11
|
+
}
|
|
12
|
+
return ref.current.previous;
|
|
13
|
+
}, [value]);
|
|
14
|
+
}
|
|
15
|
+
export { usePrevious };
|
|
16
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","usePrevious","value","ref","useRef","previous","useMemo","current"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAEhB,SAASC,YAAeC,KAAA,EAAa;EAC1C,MAAMC,GAAA,GAAMH,KAAA,CAAMI,MAAA,CAAO;IAAEF,KAAA;IAAOG,QAAA,EAAUH;EAAM,CAAC;EAKnD,OAAOF,KAAA,CAAMM,OAAA,CAAQ,MAAM;IACzB,IAAIH,GAAA,CAAII,OAAA,CAAQL,KAAA,KAAUA,KAAA,EAAO;MAC/BC,GAAA,CAAII,OAAA,CAAQF,QAAA,GAAWF,GAAA,CAAII,OAAA,CAAQL,KAAA;MACnCC,GAAA,CAAII,OAAA,CAAQL,KAAA,GAAQA,KAAA;IACtB;IACA,OAAOC,GAAA,CAAII,OAAA,CAAQF,QAAA;EACrB,GAAG,CAACH,KAAK,CAAC;AACZ","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
function usePrevious(value) {
|
|
3
|
+
var ref = React.useRef({
|
|
4
|
+
value,
|
|
5
|
+
previous: value
|
|
6
|
+
});
|
|
7
|
+
return React.useMemo(function () {
|
|
8
|
+
if (ref.current.value !== value) {
|
|
9
|
+
ref.current.previous = ref.current.value;
|
|
10
|
+
ref.current.value = value;
|
|
11
|
+
}
|
|
12
|
+
return ref.current.previous;
|
|
13
|
+
}, [value]);
|
|
14
|
+
}
|
|
15
|
+
export { usePrevious };
|
|
16
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","usePrevious","value","ref","useRef","previous","useMemo","current"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAEA,YAAYA,KAAA,MAAW;AAEhB,SAASC,YAAeC,KAAA,EAAa;EAC1C,IAAAC,GAAM,GAAAH,KAAM,CAAAI,MAAM;IAKlBF,KAAO;IACLG,QAAQ,EAAAH;EACN;EACA,OAAAF,KAAI,CAAAM,OAAQ,aAAQ;IACtB,IAAAH,GAAA,CAAAI,OAAA,CAAAL,KAAA,KAAAA,KAAA;MACAC,GAAA,CAAAI,OAAW,CAAAF,QAAQ,GAAAF,GAAA,CAAAI,OAAA,CAAAL,KAAA;MACjBC,GAAA,CAAAI,OAAM,CAAAL,KAAA,GAAAA,KAAA;IACZ","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/use-previous",
|
|
3
|
+
"version": "2.0.0-rc.41-hanzoai.5",
|
|
4
|
+
"files": [
|
|
5
|
+
"src",
|
|
6
|
+
"types",
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "dist/cjs",
|
|
12
|
+
"module": "dist/esm",
|
|
13
|
+
"types": "./types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./types/index.d.ts",
|
|
18
|
+
"react-native": "./dist/esm/index.native.js",
|
|
19
|
+
"browser": "./dist/esm/index.mjs",
|
|
20
|
+
"module": "./dist/esm/index.mjs",
|
|
21
|
+
"import": "./dist/esm/index.mjs",
|
|
22
|
+
"require": "./dist/cjs/index.cjs",
|
|
23
|
+
"default": "./dist/esm/index.mjs"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "hanzogui-build",
|
|
31
|
+
"watch": "hanzogui-build --watch",
|
|
32
|
+
"clean": "hanzogui-build clean",
|
|
33
|
+
"clean:build": "hanzogui-build clean:build"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@hanzogui/build": "2.0.0-rc.41-hanzoai.5",
|
|
37
|
+
"react": ">=19"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": ">=19"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// via radix-ui
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
|
|
5
|
+
export function usePrevious<T>(value: T): T {
|
|
6
|
+
const ref = React.useRef({ value, previous: value })
|
|
7
|
+
|
|
8
|
+
// We compare values before making an update to ensure that
|
|
9
|
+
// a change has been made. This ensures the previous value is
|
|
10
|
+
// persisted correctly between renders.
|
|
11
|
+
return React.useMemo(() => {
|
|
12
|
+
if (ref.current.value !== value) {
|
|
13
|
+
ref.current.previous = ref.current.value
|
|
14
|
+
ref.current.value = value
|
|
15
|
+
}
|
|
16
|
+
return ref.current.previous
|
|
17
|
+
}, [value])
|
|
18
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAIA,OAAO,iBAAS,YAAY,GAAG,OAAO,IAAI",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/index.ts"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"// via radix-ui\n\nimport * as React from 'react'\n\nexport function usePrevious<T>(value: T): T {\n const ref = React.useRef({ value, previous: value })\n\n // We compare values before making an update to ensure that\n // a change has been made. This ensures the previous value is\n // persisted correctly between renders.\n return React.useMemo(() => {\n if (ref.current.value !== value) {\n ref.current.previous = ref.current.value\n ref.current.value = value\n }\n return ref.current.previous\n }, [value])\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|