@tamagui/use-previous 1.45.9
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/index.js +39 -0
- package/dist/cjs/index.js.map +6 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/index.js.map +6 -0
- package/package.json +34 -0
- package/src/index.ts +18 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
usePrevious: () => usePrevious
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
function usePrevious(value) {
|
|
26
|
+
const ref = (0, import_react.useRef)({ value, previous: value });
|
|
27
|
+
return (0, import_react.useMemo)(() => {
|
|
28
|
+
if (ref.current.value !== value) {
|
|
29
|
+
ref.current.previous = ref.current.value;
|
|
30
|
+
ref.current.value = value;
|
|
31
|
+
}
|
|
32
|
+
return ref.current.previous;
|
|
33
|
+
}, [value]);
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
usePrevious
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAgC;AAEzB,SAAS,YAAe,OAAU;AACvC,QAAM,UAAM,qBAAO,EAAE,OAAO,UAAU,MAAM,CAAC;AAK7C,aAAO,sBAAQ,MAAM;AACnB,QAAI,IAAI,QAAQ,UAAU,OAAO;AAC/B,UAAI,QAAQ,WAAW,IAAI,QAAQ;AACnC,UAAI,QAAQ,QAAQ;AAAA,IACtB;AACA,WAAO,IAAI,QAAQ;AAAA,EACrB,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
function usePrevious(value) {
|
|
3
|
+
const ref = useRef({ value, previous: value });
|
|
4
|
+
return useMemo(() => {
|
|
5
|
+
if (ref.current.value !== value) {
|
|
6
|
+
ref.current.previous = ref.current.value;
|
|
7
|
+
ref.current.value = value;
|
|
8
|
+
}
|
|
9
|
+
return ref.current.previous;
|
|
10
|
+
}, [value]);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
usePrevious
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": "AAEA,SAAS,SAAS,cAAc;AAEzB,SAAS,YAAe,OAAU;AACvC,QAAM,MAAM,OAAO,EAAE,OAAO,UAAU,MAAM,CAAC;AAK7C,SAAO,QAAQ,MAAM;AACnB,QAAI,IAAI,QAAQ,UAAU,OAAO;AAC/B,UAAI,QAAQ,WAAW,IAAI,QAAQ;AACnC,UAAI,QAAQ,QAAQ;AAAA,IACtB;AACA,WAAO,IAAI,QAAQ;AAAA,EACrB,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/use-previous",
|
|
3
|
+
"version": "1.45.9",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"main": "dist/cjs",
|
|
6
|
+
"module": "dist/esm",
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"types",
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tamagui-build",
|
|
14
|
+
"watch": "tamagui-build --watch",
|
|
15
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
16
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply src",
|
|
17
|
+
"clean": "tamagui-build clean",
|
|
18
|
+
"clean:build": "tamagui-build clean:build"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tamagui/build": "1.45.9"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./package.json": "./package.json",
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./types/index.d.ts",
|
|
27
|
+
"import": "./dist/esm/index.js",
|
|
28
|
+
"require": "./dist/cjs/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// via radix-ui
|
|
2
|
+
|
|
3
|
+
import { useMemo, useRef } from 'react'
|
|
4
|
+
|
|
5
|
+
export function usePrevious<T>(value: T) {
|
|
6
|
+
const ref = 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 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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAatC"}
|