@raegen/react-use-prev 0.1.0
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/README.md +98 -0
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nikola Pavlovic
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @raegen/react-use-prev
|
|
2
|
+
|
|
3
|
+
The `usePrevious` hook that's actually correct when you **render** the previous value.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { usePrev } from '@raegen/react-use-prev';
|
|
7
|
+
|
|
8
|
+
const prev = usePrev(value);
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Returns the previous *distinct* value of `value`: the value as of the most recent commit
|
|
12
|
+
at which `Object.is` saw it change. Correct, rendered immediately, pure, and with no extra
|
|
13
|
+
render.
|
|
14
|
+
|
|
15
|
+
## Why another one?
|
|
16
|
+
|
|
17
|
+
Every popular `usePrevious` is wrong in a different way when you display the previous value,
|
|
18
|
+
not just diff it inside an effect:
|
|
19
|
+
|
|
20
|
+
| Property | react-use `usePrevious` | ref-in-effect | usehooks-ts¹ | **`usePrev`** |
|
|
21
|
+
|---|:---:|:---:|:---:|:---:|
|
|
22
|
+
| Correct previous-*distinct* value | ❌ collapses | ✅ | ✅ | ✅ |
|
|
23
|
+
| Rendered immediately (no lag) | ❌ wrong value | ❌ one behind | ✅ | ✅ |
|
|
24
|
+
| No ref mutation during render | ✅ | ✅ | ❌ | ✅ |
|
|
25
|
+
| Self-delivering (no extra trigger needed) | ❌ | ❌ | n/a | ✅ |
|
|
26
|
+
| No extra render | ✅ | ✅ | ✅ | ✅ |
|
|
27
|
+
|
|
28
|
+
¹ usehooks-ts `usePrevious` and react-use `usePreviousDistinct` share the same mechanism
|
|
29
|
+
(refs mutated during render), so they share the same failure mode: impure under StrictMode
|
|
30
|
+
and concurrent rendering.
|
|
31
|
+
|
|
32
|
+
- **react-use `usePrevious`** returns "value at last render," so any unrelated re-render
|
|
33
|
+
collapses the previous value into the current one.
|
|
34
|
+
- **The ref-in-effect pattern** renders one transition behind: the ref is advanced *after*
|
|
35
|
+
the render that needed it, and a ref write schedules no re-render.
|
|
36
|
+
- **usehooks-ts** tracks the value correctly but mutates refs *during render*, which breaks
|
|
37
|
+
the rules of React under StrictMode double-invocation and concurrent rendering.
|
|
38
|
+
|
|
39
|
+
`usePrev` reads a local ref during render (never mutates one there) and advances it only in a
|
|
40
|
+
post-commit effect. The read-time fallback returns the soon-to-be-previous value on the
|
|
41
|
+
transition render, so the correct value is on screen immediately with no extra render.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm install @raegen/react-use-prev
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`react` is a peer dependency (`>=16.8`). Works with React 16.8 through 19.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { usePrev } from '@raegen/react-use-prev';
|
|
55
|
+
|
|
56
|
+
function Price({ amount }: { amount: number }) {
|
|
57
|
+
const prevAmount = usePrev(amount);
|
|
58
|
+
const direction = prevAmount === undefined ? null : amount > prevAmount ? '▲' : '▼';
|
|
59
|
+
return <span>{amount} {direction}</span>;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Provide a second argument to set the first-render value (otherwise it's `undefined`):
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const prev = usePrev(value, value); // first render returns the current value instead of undefined
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## The invariant
|
|
70
|
+
|
|
71
|
+
> On every committed render, `usePrev` returns the value held at the previous commit where
|
|
72
|
+
> `Object.is(value, previousValue)` was `false` — or `initialValue` (default `undefined`)
|
|
73
|
+
> before any such change.
|
|
74
|
+
|
|
75
|
+
## Types
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
function usePrev<T>(value: T): T | undefined; // no initial value
|
|
79
|
+
function usePrev<T>(value: T, initialValue: T): T; // with an initial value
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The first render returns `initialValue`, so without one the return type is `T | undefined`;
|
|
83
|
+
with one it's `T`.
|
|
84
|
+
|
|
85
|
+
## Gotchas
|
|
86
|
+
|
|
87
|
+
**Comparison is `Object.is`** — the same comparison React uses for dependency arrays. If you
|
|
88
|
+
pass a referentially-unstable value (a fresh object/array literal every render), every render
|
|
89
|
+
counts as a change, exactly as it would in a `useEffect` dependency array. Pass primitives or
|
|
90
|
+
memoized values. A custom comparator (for deep/structural equality) is planned for a future
|
|
91
|
+
release.
|
|
92
|
+
|
|
93
|
+
**It's a client hook.** Like any hook using `useEffect`, call it from a Client Component.
|
|
94
|
+
Its first render is deterministic (`initialValue`), so it hydrates without a mismatch.
|
|
95
|
+
|
|
96
|
+
## License
|
|
97
|
+
|
|
98
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
// src/usePrev.ts
|
|
6
|
+
function usePrev(value, initialValue) {
|
|
7
|
+
const ref = react.useRef({
|
|
8
|
+
previous: initialValue,
|
|
9
|
+
current: value
|
|
10
|
+
});
|
|
11
|
+
const { previous, current } = ref.current;
|
|
12
|
+
react.useEffect(() => {
|
|
13
|
+
ref.current = {
|
|
14
|
+
previous: ref.current.current,
|
|
15
|
+
current: value
|
|
16
|
+
};
|
|
17
|
+
}, [value]);
|
|
18
|
+
return !Object.is(current, value) ? current : previous;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.usePrev = usePrev;
|
|
22
|
+
//# sourceMappingURL=index.cjs.map
|
|
23
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePrev.ts"],"names":["useRef","useEffect"],"mappings":";;;;;AAgDO,SAAS,OAAA,CAAW,OAAU,YAAA,EAAkB;AACrD,EAAA,MAAM,MAAMA,YAAA,CAAgD;AAAA,IAC1D,QAAA,EAAU,YAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,MAAM,EAAE,QAAA,EAAU,OAAA,EAAQ,GAAI,GAAA,CAAI,OAAA;AAElC,EAAAC,eAAA,CAAU,MAAM;AACd,IAAA,GAAA,CAAI,OAAA,GAAU;AAAA,MACZ,QAAA,EAAU,IAAI,OAAA,CAAQ,OAAA;AAAA,MACtB,OAAA,EAAS;AAAA,KACX;AAAA,EACF,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,OAAO,CAAC,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,KAAK,IAAI,OAAA,GAAU,QAAA;AAChD","file":"index.cjs","sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * Returns the previous *distinct* value of `value` — the value as of the most\n * recent commit at which `Object.is` saw it change.\n *\n * Why this exists: the common `usePrevious` implementations are each wrong in a\n * different way when you *render* the previous value.\n * - react-use `usePrevious` returns \"value at last render\", so any unrelated\n * re-render collapses previous into current.\n * - The ref-in-effect pattern renders one transition behind (the ref is\n * advanced after the render that needed it, and a ref write schedules no\n * re-render).\n * - usehooks-ts / react-use `usePreviousDistinct` track the value correctly\n * but mutate a ref *during render*, which is impure under StrictMode and\n * concurrent rendering.\n *\n * `usePrev` is correct, renders the right value immediately, adds no extra\n * render, and never mutates a ref during render.\n *\n * Invariant: on every committed render it returns the value held at the\n * previous commit where `Object.is(value, prevValue)` was false (or\n * `initialValue` before any such change).\n *\n * Mechanism (the read-time fallback is the trick):\n *\n * render | value | ref @ render | !Object.is(cur,value) | returns | effect sets ref\n * -------+-------+--------------+-----------------------+---------+----------------\n * mount | A | {prev:init, | false | init | {prev:A, cur:A}\n * | | cur:A} | | |\n * A -> B | B | {prev:A, | true | A | {prev:A, cur:B}\n * | | cur:A} | | |\n * (rerun)| B | {prev:A, | false | A | (dep [value] same)\n * | | cur:B} | | |\n * B -> C | C | {prev:A, | true | B | {prev:B, cur:C}\n * | | cur:B} | | |\n *\n * Note: comparison is `Object.is`, exactly like a React dependency array. If\n * you pass a referentially-unstable value (a fresh object/array each render),\n * every render counts as a change — pass primitives or memoized values, or\n * wait for the custom-comparator option in a future release.\n *\n * @param value the value to track\n * @param initialValue the value returned on the first render; defaults to\n * `undefined` (classic `usePrevious` behavior)\n */\nexport function usePrev<T>(value: T): T | undefined;\nexport function usePrev<T>(value: T, initialValue: T): T;\nexport function usePrev<T>(value: T, initialValue?: T) {\n const ref = useRef<{ previous: T | undefined; current: T }>({\n previous: initialValue,\n current: value,\n });\n\n const { previous, current } = ref.current;\n\n useEffect(() => {\n ref.current = {\n previous: ref.current.current,\n current: value,\n };\n }, [value]);\n\n return !Object.is(current, value) ? current : previous;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the previous *distinct* value of `value` — the value as of the most
|
|
3
|
+
* recent commit at which `Object.is` saw it change.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: the common `usePrevious` implementations are each wrong in a
|
|
6
|
+
* different way when you *render* the previous value.
|
|
7
|
+
* - react-use `usePrevious` returns "value at last render", so any unrelated
|
|
8
|
+
* re-render collapses previous into current.
|
|
9
|
+
* - The ref-in-effect pattern renders one transition behind (the ref is
|
|
10
|
+
* advanced after the render that needed it, and a ref write schedules no
|
|
11
|
+
* re-render).
|
|
12
|
+
* - usehooks-ts / react-use `usePreviousDistinct` track the value correctly
|
|
13
|
+
* but mutate a ref *during render*, which is impure under StrictMode and
|
|
14
|
+
* concurrent rendering.
|
|
15
|
+
*
|
|
16
|
+
* `usePrev` is correct, renders the right value immediately, adds no extra
|
|
17
|
+
* render, and never mutates a ref during render.
|
|
18
|
+
*
|
|
19
|
+
* Invariant: on every committed render it returns the value held at the
|
|
20
|
+
* previous commit where `Object.is(value, prevValue)` was false (or
|
|
21
|
+
* `initialValue` before any such change).
|
|
22
|
+
*
|
|
23
|
+
* Mechanism (the read-time fallback is the trick):
|
|
24
|
+
*
|
|
25
|
+
* render | value | ref @ render | !Object.is(cur,value) | returns | effect sets ref
|
|
26
|
+
* -------+-------+--------------+-----------------------+---------+----------------
|
|
27
|
+
* mount | A | {prev:init, | false | init | {prev:A, cur:A}
|
|
28
|
+
* | | cur:A} | | |
|
|
29
|
+
* A -> B | B | {prev:A, | true | A | {prev:A, cur:B}
|
|
30
|
+
* | | cur:A} | | |
|
|
31
|
+
* (rerun)| B | {prev:A, | false | A | (dep [value] same)
|
|
32
|
+
* | | cur:B} | | |
|
|
33
|
+
* B -> C | C | {prev:A, | true | B | {prev:B, cur:C}
|
|
34
|
+
* | | cur:B} | | |
|
|
35
|
+
*
|
|
36
|
+
* Note: comparison is `Object.is`, exactly like a React dependency array. If
|
|
37
|
+
* you pass a referentially-unstable value (a fresh object/array each render),
|
|
38
|
+
* every render counts as a change — pass primitives or memoized values, or
|
|
39
|
+
* wait for the custom-comparator option in a future release.
|
|
40
|
+
*
|
|
41
|
+
* @param value the value to track
|
|
42
|
+
* @param initialValue the value returned on the first render; defaults to
|
|
43
|
+
* `undefined` (classic `usePrevious` behavior)
|
|
44
|
+
*/
|
|
45
|
+
declare function usePrev<T>(value: T): T | undefined;
|
|
46
|
+
declare function usePrev<T>(value: T, initialValue: T): T;
|
|
47
|
+
|
|
48
|
+
export { usePrev };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the previous *distinct* value of `value` — the value as of the most
|
|
3
|
+
* recent commit at which `Object.is` saw it change.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: the common `usePrevious` implementations are each wrong in a
|
|
6
|
+
* different way when you *render* the previous value.
|
|
7
|
+
* - react-use `usePrevious` returns "value at last render", so any unrelated
|
|
8
|
+
* re-render collapses previous into current.
|
|
9
|
+
* - The ref-in-effect pattern renders one transition behind (the ref is
|
|
10
|
+
* advanced after the render that needed it, and a ref write schedules no
|
|
11
|
+
* re-render).
|
|
12
|
+
* - usehooks-ts / react-use `usePreviousDistinct` track the value correctly
|
|
13
|
+
* but mutate a ref *during render*, which is impure under StrictMode and
|
|
14
|
+
* concurrent rendering.
|
|
15
|
+
*
|
|
16
|
+
* `usePrev` is correct, renders the right value immediately, adds no extra
|
|
17
|
+
* render, and never mutates a ref during render.
|
|
18
|
+
*
|
|
19
|
+
* Invariant: on every committed render it returns the value held at the
|
|
20
|
+
* previous commit where `Object.is(value, prevValue)` was false (or
|
|
21
|
+
* `initialValue` before any such change).
|
|
22
|
+
*
|
|
23
|
+
* Mechanism (the read-time fallback is the trick):
|
|
24
|
+
*
|
|
25
|
+
* render | value | ref @ render | !Object.is(cur,value) | returns | effect sets ref
|
|
26
|
+
* -------+-------+--------------+-----------------------+---------+----------------
|
|
27
|
+
* mount | A | {prev:init, | false | init | {prev:A, cur:A}
|
|
28
|
+
* | | cur:A} | | |
|
|
29
|
+
* A -> B | B | {prev:A, | true | A | {prev:A, cur:B}
|
|
30
|
+
* | | cur:A} | | |
|
|
31
|
+
* (rerun)| B | {prev:A, | false | A | (dep [value] same)
|
|
32
|
+
* | | cur:B} | | |
|
|
33
|
+
* B -> C | C | {prev:A, | true | B | {prev:B, cur:C}
|
|
34
|
+
* | | cur:B} | | |
|
|
35
|
+
*
|
|
36
|
+
* Note: comparison is `Object.is`, exactly like a React dependency array. If
|
|
37
|
+
* you pass a referentially-unstable value (a fresh object/array each render),
|
|
38
|
+
* every render counts as a change — pass primitives or memoized values, or
|
|
39
|
+
* wait for the custom-comparator option in a future release.
|
|
40
|
+
*
|
|
41
|
+
* @param value the value to track
|
|
42
|
+
* @param initialValue the value returned on the first render; defaults to
|
|
43
|
+
* `undefined` (classic `usePrevious` behavior)
|
|
44
|
+
*/
|
|
45
|
+
declare function usePrev<T>(value: T): T | undefined;
|
|
46
|
+
declare function usePrev<T>(value: T, initialValue: T): T;
|
|
47
|
+
|
|
48
|
+
export { usePrev };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// src/usePrev.ts
|
|
4
|
+
function usePrev(value, initialValue) {
|
|
5
|
+
const ref = useRef({
|
|
6
|
+
previous: initialValue,
|
|
7
|
+
current: value
|
|
8
|
+
});
|
|
9
|
+
const { previous, current } = ref.current;
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
ref.current = {
|
|
12
|
+
previous: ref.current.current,
|
|
13
|
+
current: value
|
|
14
|
+
};
|
|
15
|
+
}, [value]);
|
|
16
|
+
return !Object.is(current, value) ? current : previous;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { usePrev };
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/usePrev.ts"],"names":[],"mappings":";;;AAgDO,SAAS,OAAA,CAAW,OAAU,YAAA,EAAkB;AACrD,EAAA,MAAM,MAAM,MAAA,CAAgD;AAAA,IAC1D,QAAA,EAAU,YAAA;AAAA,IACV,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,MAAM,EAAE,QAAA,EAAU,OAAA,EAAQ,GAAI,GAAA,CAAI,OAAA;AAElC,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,GAAA,CAAI,OAAA,GAAU;AAAA,MACZ,QAAA,EAAU,IAAI,OAAA,CAAQ,OAAA;AAAA,MACtB,OAAA,EAAS;AAAA,KACX;AAAA,EACF,CAAA,EAAG,CAAC,KAAK,CAAC,CAAA;AAEV,EAAA,OAAO,CAAC,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,KAAK,IAAI,OAAA,GAAU,QAAA;AAChD","file":"index.js","sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * Returns the previous *distinct* value of `value` — the value as of the most\n * recent commit at which `Object.is` saw it change.\n *\n * Why this exists: the common `usePrevious` implementations are each wrong in a\n * different way when you *render* the previous value.\n * - react-use `usePrevious` returns \"value at last render\", so any unrelated\n * re-render collapses previous into current.\n * - The ref-in-effect pattern renders one transition behind (the ref is\n * advanced after the render that needed it, and a ref write schedules no\n * re-render).\n * - usehooks-ts / react-use `usePreviousDistinct` track the value correctly\n * but mutate a ref *during render*, which is impure under StrictMode and\n * concurrent rendering.\n *\n * `usePrev` is correct, renders the right value immediately, adds no extra\n * render, and never mutates a ref during render.\n *\n * Invariant: on every committed render it returns the value held at the\n * previous commit where `Object.is(value, prevValue)` was false (or\n * `initialValue` before any such change).\n *\n * Mechanism (the read-time fallback is the trick):\n *\n * render | value | ref @ render | !Object.is(cur,value) | returns | effect sets ref\n * -------+-------+--------------+-----------------------+---------+----------------\n * mount | A | {prev:init, | false | init | {prev:A, cur:A}\n * | | cur:A} | | |\n * A -> B | B | {prev:A, | true | A | {prev:A, cur:B}\n * | | cur:A} | | |\n * (rerun)| B | {prev:A, | false | A | (dep [value] same)\n * | | cur:B} | | |\n * B -> C | C | {prev:A, | true | B | {prev:B, cur:C}\n * | | cur:B} | | |\n *\n * Note: comparison is `Object.is`, exactly like a React dependency array. If\n * you pass a referentially-unstable value (a fresh object/array each render),\n * every render counts as a change — pass primitives or memoized values, or\n * wait for the custom-comparator option in a future release.\n *\n * @param value the value to track\n * @param initialValue the value returned on the first render; defaults to\n * `undefined` (classic `usePrevious` behavior)\n */\nexport function usePrev<T>(value: T): T | undefined;\nexport function usePrev<T>(value: T, initialValue: T): T;\nexport function usePrev<T>(value: T, initialValue?: T) {\n const ref = useRef<{ previous: T | undefined; current: T }>({\n previous: initialValue,\n current: value,\n });\n\n const { previous, current } = ref.current;\n\n useEffect(() => {\n ref.current = {\n previous: ref.current.current,\n current: value,\n };\n }, [value]);\n\n return !Object.is(current, value) ? current : previous;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@raegen/react-use-prev",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The correct usePrevious: renders the previous distinct value immediately, purely, with no extra render.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"hook",
|
|
8
|
+
"hooks",
|
|
9
|
+
"use-previous",
|
|
10
|
+
"usePrevious",
|
|
11
|
+
"previous",
|
|
12
|
+
"previous-value",
|
|
13
|
+
"usePrev",
|
|
14
|
+
"react-hooks"
|
|
15
|
+
],
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "raegen",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/raegen/react-use-prev.git"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/raegen/react-use-prev#readme",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/raegen/react-use-prev/issues"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"default": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/index.d.cts",
|
|
39
|
+
"default": "./dist/index.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"lint:pkg": "publint && attw --pack .",
|
|
53
|
+
"prepublishOnly": "npm run build"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": ">=16.8.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@arethetypeswrong/cli": "^0.18.4",
|
|
60
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
61
|
+
"@testing-library/react": "^16.1.0",
|
|
62
|
+
"@types/react": "^19.0.7",
|
|
63
|
+
"@types/react-dom": "^19.0.3",
|
|
64
|
+
"jsdom": "^25.0.1",
|
|
65
|
+
"publint": "^0.3.2",
|
|
66
|
+
"react": "^19.0.0",
|
|
67
|
+
"react-dom": "^19.0.0",
|
|
68
|
+
"tsup": "^8.3.5",
|
|
69
|
+
"typescript": "^5.7.3",
|
|
70
|
+
"vitest": "^2.1.8"
|
|
71
|
+
},
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=18"
|
|
74
|
+
},
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public",
|
|
77
|
+
"provenance": true
|
|
78
|
+
}
|
|
79
|
+
}
|