@1hook/use-previous 0.0.1-beta.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.
@@ -0,0 +1,6 @@
1
+ type UsePreviousOptions<T> = {
2
+ isEqual?: (prev: T | undefined, next: T) => boolean;
3
+ };
4
+ declare function usePrevious<T>(value: T, { isEqual }?: UsePreviousOptions<T>): T | undefined;
5
+
6
+ export { type UsePreviousOptions, usePrevious };
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+
3
+ // src/index.ts
4
+ function usePrevious(value, { isEqual = Object.is } = {}) {
5
+ const [state, setState] = React.useState({
6
+ prev: void 0,
7
+ current: value
8
+ });
9
+ if (!isEqual(value, state.current)) {
10
+ setState({
11
+ prev: state.current,
12
+ current: value
13
+ });
14
+ }
15
+ return state.prev;
16
+ }
17
+
18
+ export { usePrevious };
19
+ //# sourceMappingURL=index.js.map
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAMO,SAAS,WAAA,CACd,OACA,EAAE,OAAA,GAAU,OAAO,EAAG,EAAA,GAA2B,EAClC,EAAA;AACf,EAAA,MAAM,CAAC,KAAA,EAAO,QAAQ,CAAA,GAAI,MAAM,QAAS,CAAA;AAAA,IACvC,IAAM,EAAA,MAAA;AAAA,IACN,OAAS,EAAA;AAAA,GACV,CAAA;AAED,EAAA,IAAI,CAAC,OAAA,CAAQ,KAAO,EAAA,KAAA,CAAM,OAAO,CAAG,EAAA;AAClC,IAAS,QAAA,CAAA;AAAA,MACP,MAAM,KAAM,CAAA,OAAA;AAAA,MACZ,OAAS,EAAA;AAAA,KACV,CAAA;AAAA;AAGH,EAAA,OAAO,KAAM,CAAA,IAAA;AACf","file":"index.js","sourcesContent":["import React from 'react'\n\nexport type UsePreviousOptions<T> = {\n isEqual?: (prev: T | undefined, next: T) => boolean\n}\n\nexport function usePrevious<T>(\n value: T,\n { isEqual = Object.is }: UsePreviousOptions<T> = {} as any,\n): T | undefined {\n const [state, setState] = React.useState({\n prev: undefined as T | undefined,\n current: value,\n })\n\n if (!isEqual(value, state.current)) {\n setState({\n prev: state.current,\n current: value,\n })\n }\n\n return state.prev\n}\n"]}
Binary file
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@1hook/use-previous",
3
+ "version": "0.0.1-beta.1",
4
+ "files": [
5
+ "dist",
6
+ "README.md"
7
+ ],
8
+ "type": "module",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "peerDependencies": {
17
+ "@types/react": ">=18.0.0 || >=19.0.0",
18
+ "@types/react-dom": ">=18.0.0 || >=19.0.0",
19
+ "react": ">=18.0.0 || >=19.0.0",
20
+ "react-dom": ">=18.0.0 || >=19.0.0"
21
+ },
22
+ "tag": "beta",
23
+ "scripts": {
24
+ "build": "NODE_ENV=production tsup",
25
+ "dev": "concurrently \"tsup --watch\" \"vitest\"",
26
+ "test": "vitest run && tsc --noEmit",
27
+ "lint": "eslint . && tsc --noEmit",
28
+ "lint:eslint": "eslint .",
29
+ "lint:typescript": "tsc --noEmit"
30
+ }
31
+ }