@radix-ui/react-use-previous 0.0.0-20250116175529

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # `react-use-previous`
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ yarn add @radix-ui/react-use-previous
7
+ # or
8
+ $ npm install @radix-ui/react-use-previous
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ This is an internal utility, not intended for public usage.
@@ -0,0 +1,3 @@
1
+ declare function usePrevious<T>(value: T): T;
2
+
3
+ export { usePrevious };
@@ -0,0 +1,3 @@
1
+ declare function usePrevious<T>(value: T): T;
2
+
3
+ export { usePrevious };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/react/use-previous/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ usePrevious: () => usePrevious
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // packages/react/use-previous/src/usePrevious.tsx
38
+ var React = __toESM(require("react"));
39
+ function usePrevious(value) {
40
+ const ref = React.useRef({ value, previous: value });
41
+ return React.useMemo(() => {
42
+ if (ref.current.value !== value) {
43
+ ref.current.previous = ref.current.value;
44
+ ref.current.value = value;
45
+ }
46
+ return ref.current.previous;
47
+ }, [value]);
48
+ }
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/usePrevious.tsx"],
4
+ "sourcesContent": ["export { usePrevious } from './usePrevious';\n", "import * as React from 'react';\n\nfunction usePrevious<T>(value: 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\nexport { usePrevious };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AAEvB,SAAS,YAAe,OAAU;AAChC,QAAM,MAAY,aAAO,EAAE,OAAO,UAAU,MAAM,CAAC;AAKnD,SAAa,cAAQ,MAAM;AACzB,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;",
6
+ "names": []
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,16 @@
1
+ // packages/react/use-previous/src/usePrevious.tsx
2
+ import * as React from "react";
3
+ function usePrevious(value) {
4
+ const ref = React.useRef({ value, previous: value });
5
+ return React.useMemo(() => {
6
+ if (ref.current.value !== value) {
7
+ ref.current.previous = ref.current.value;
8
+ ref.current.value = value;
9
+ }
10
+ return ref.current.previous;
11
+ }, [value]);
12
+ }
13
+ export {
14
+ usePrevious
15
+ };
16
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/usePrevious.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\n\nfunction usePrevious<T>(value: 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\nexport { usePrevious };\n"],
5
+ "mappings": ";AAAA,YAAY,WAAW;AAEvB,SAAS,YAAe,OAAU;AAChC,QAAM,MAAY,aAAO,EAAE,OAAO,UAAU,MAAM,CAAC;AAKnD,SAAa,cAAQ,MAAM;AACzB,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;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@radix-ui/react-use-previous",
3
+ "version": "0.0.0-20250116175529",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": {
7
+ "import": {
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ }
16
+ },
17
+ "source": "./src/index.ts",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "peerDependencies": {
30
+ "@types/react": "*",
31
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@types/react": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "homepage": "https://radix-ui.com/primitives",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/radix-ui/primitives.git"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/radix-ui/primitives/issues"
45
+ }
46
+ }