use-state-with-ref 0.1.1-main.bf0fd65 → 0.2.0-main.530523c

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,12 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ import { useRefFrom } from 'use-ref-from';
3
+
4
+ type ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;
5
+ declare function useStateWithRef<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];
6
+ declare function useStateWithRef<S = undefined>(): [
7
+ S | undefined,
8
+ Dispatch<SetStateAction<S | undefined>>,
9
+ ReadonlyRefObject<S | undefined>
10
+ ];
11
+
12
+ export { useStateWithRef };
@@ -0,0 +1,12 @@
1
+ import { Dispatch, SetStateAction } from 'react';
2
+ import { useRefFrom } from 'use-ref-from';
3
+
4
+ type ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;
5
+ declare function useStateWithRef<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];
6
+ declare function useStateWithRef<S = undefined>(): [
7
+ S | undefined,
8
+ Dispatch<SetStateAction<S | undefined>>,
9
+ ReadonlyRefObject<S | undefined>
10
+ ];
11
+
12
+ export { useStateWithRef };
@@ -0,0 +1,38 @@
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
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ useStateWithRef: () => useStateWithRef
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/useStateWithRef.ts
28
+ var import_react = require("react");
29
+ var import_use_ref_from = require("use-ref-from");
30
+ function useStateWithRef(initialState) {
31
+ const [value, setter] = (0, import_react.useState)(initialState);
32
+ return Object.freeze([value, setter, (0, import_use_ref_from.useRefFrom)(value)]);
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ useStateWithRef
37
+ });
38
+ //# sourceMappingURL=use-state-with-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/useStateWithRef.ts"],"sourcesContent":["import useStateWithRef from './useStateWithRef';\n\nexport { useStateWithRef };\n","import { type Dispatch, type SetStateAction, useState } from 'react';\nimport { useRefFrom } from 'use-ref-from';\n\ntype ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;\n\nexport default function useStateWithRef<S>(\n initialState: S | (() => S)\n): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];\n\nexport default function useStateWithRef<S = undefined>(): [\n S | undefined,\n Dispatch<SetStateAction<S | undefined>>,\n ReadonlyRefObject<S | undefined>\n];\n\nexport default function useStateWithRef<S>(\n initialState?: S | (() => S)\n): readonly [S | undefined, Dispatch<SetStateAction<S | undefined>>, ReadonlyRefObject<S | undefined>] {\n const [value, setter] = useState<S | undefined>(initialState);\n\n return Object.freeze([value, setter, useRefFrom(value)]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA6D;AAC7D,0BAA2B;AAcZ,SAAR,gBACL,cACqG;AACrG,QAAM,CAAC,OAAO,MAAM,QAAI,uBAAwB,YAAY;AAE5D,SAAO,OAAO,OAAO,CAAC,OAAO,YAAQ,gCAAW,KAAK,CAAC,CAAC;AACzD;","names":[]}
@@ -0,0 +1,11 @@
1
+ // src/useStateWithRef.ts
2
+ import { useState } from "react";
3
+ import { useRefFrom } from "use-ref-from";
4
+ function useStateWithRef(initialState) {
5
+ const [value, setter] = useState(initialState);
6
+ return Object.freeze([value, setter, useRefFrom(value)]);
7
+ }
8
+ export {
9
+ useStateWithRef
10
+ };
11
+ //# sourceMappingURL=use-state-with-ref.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/useStateWithRef.ts"],"sourcesContent":["import { type Dispatch, type SetStateAction, useState } from 'react';\nimport { useRefFrom } from 'use-ref-from';\n\ntype ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;\n\nexport default function useStateWithRef<S>(\n initialState: S | (() => S)\n): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];\n\nexport default function useStateWithRef<S = undefined>(): [\n S | undefined,\n Dispatch<SetStateAction<S | undefined>>,\n ReadonlyRefObject<S | undefined>\n];\n\nexport default function useStateWithRef<S>(\n initialState?: S | (() => S)\n): readonly [S | undefined, Dispatch<SetStateAction<S | undefined>>, ReadonlyRefObject<S | undefined>] {\n const [value, setter] = useState<S | undefined>(initialState);\n\n return Object.freeze([value, setter, useRefFrom(value)]);\n}\n"],"mappings":";AAAA,SAA6C,gBAAgB;AAC7D,SAAS,kBAAkB;AAcZ,SAAR,gBACL,cACqG;AACrG,QAAM,CAAC,OAAO,MAAM,IAAI,SAAwB,YAAY;AAE5D,SAAO,OAAO,OAAO,CAAC,OAAO,QAAQ,WAAW,KAAK,CAAC,CAAC;AACzD;","names":[]}
package/package.json CHANGED
@@ -1,48 +1,30 @@
1
1
  {
2
2
  "name": "use-state-with-ref",
3
- "version": "0.1.1-main.bf0fd65",
3
+ "version": "0.2.0-main.530523c",
4
4
  "description": "React `useState` with a readonly `RefObject`.",
5
5
  "files": [
6
- "./lib/"
6
+ "./dist/"
7
7
  ],
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": {
11
- "types": "./lib/esmodules/index.d.ts",
12
- "default": "./lib/esmodules/index.js"
11
+ "types": "./dist/use-state-with-ref.d.mts",
12
+ "default": "./dist/use-state-with-ref.mjs"
13
13
  },
14
14
  "require": {
15
- "types": "./lib/commonjs/index.d.ts",
16
- "default": "./lib/commonjs/index.js"
17
- }
18
- },
19
- "./useStateWithRef": {
20
- "import": {
21
- "types": "./lib/esmodules/useStateWithRef.d.ts",
22
- "default": "./lib/esmodules/useStateWithRef.js"
23
- },
24
- "require": {
25
- "types": "./lib/commonjs/useStateWithRef.d.ts",
26
- "default": "./lib/commonjs/useStateWithRef.js"
15
+ "types": "./dist/use-state-with-ref.d.ts",
16
+ "default": "./dist/use-state-with-ref.js"
27
17
  }
28
18
  }
29
19
  },
30
- "main": "./lib/commonjs/index.js",
31
- "typings": "./lib/commonjs/index.d.ts",
20
+ "main": "./dist/use-state-with-ref.js",
21
+ "typings": "./dist/use-state-with-ref.d.ts",
32
22
  "scripts": {
33
- "build": "npm run build:babel:commonjs && npm run build:babel:esmodules && npm run build:typescript:commonjs && npm run build:typescript:esmodules",
34
- "build:babel:commonjs": "babel src --config-file ./babel.commonjs.config.json --extensions .ts,.tsx --out-dir ./lib/commonjs/",
35
- "build:babel:esmodules": "babel src --config-file ./babel.esmodules.config.json --extensions .ts,.tsx --out-dir ./lib/esmodules/",
36
- "build:typescript:commonjs": "tsc --project ./src/tsconfig.declaration.commonjs.json",
37
- "build:typescript:esmodules": "tsc --project ./src/tsconfig.declaration.esmodules.json",
38
- "bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix && npm run bump:babel",
23
+ "build": "tsup",
24
+ "bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix",
39
25
  "bump:auditfix": "npm audit fix || exit 0",
40
- "bump:babel": "npm run bump:babel:commonjs && npm run bump:babel:esmodules",
41
- "bump:babel:commonjs": "cat babel.commonjs.config.json | jq --arg CORE_JS_VERSION `[ -f node_modules/@babel/runtime-corejs3/package.json ] && cat node_modules/@babel/runtime-corejs3/package.json | jq -r .version || cat ../../node_modules/@babel/runtime-corejs3/package.json | jq -r .version` '(.plugins[] | select(.[0] == \"@babel/plugin-transform-runtime\"))[1].version = $CORE_JS_VERSION' | prettier --parser json > babel.commonjs.config.json.tmp && mv babel.commonjs.config.json.tmp babel.commonjs.config.json",
42
- "bump:babel:esmodules": "cat babel.esmodules.config.json | jq --arg CORE_JS_VERSION `[ -f node_modules/@babel/runtime-corejs3/package.json ] && cat node_modules/@babel/runtime-corejs3/package.json | jq -r .version || cat ../../node_modules/@babel/runtime-corejs3/package.json | jq -r .version` '(.plugins[] | select(.[0] == \"@babel/plugin-transform-runtime\"))[1].version = $CORE_JS_VERSION' | prettier --parser json > babel.esmodules.config.json.tmp && mv babel.esmodules.config.json.tmp babel.esmodules.config.json",
43
- "bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
44
- "bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@latest\") | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
45
- "postscaffold": "npm run bump:babel",
26
+ "bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
27
+ "bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
46
28
  "precommit": "npm run precommit:eslint && npm run precommit:typescript:production && npm run precommit:typescript:test",
47
29
  "precommit:eslint": "eslint ./src/",
48
30
  "precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
@@ -95,9 +77,6 @@
95
77
  "react": ">=16.8.0"
96
78
  },
97
79
  "devDependencies": {
98
- "@babel/cli": "^7.23.4",
99
- "@babel/core": "^7.23.6",
100
- "@babel/plugin-transform-runtime": "^7.23.6",
101
80
  "@babel/preset-env": "^7.23.6",
102
81
  "@babel/preset-react": "^7.23.3",
103
82
  "@babel/preset-typescript": "^7.23.3",
@@ -111,11 +90,11 @@
111
90
  "jest-environment-jsdom": "^29.7.0",
112
91
  "react": "^18.2.0",
113
92
  "react-test-renderer": "^18.2.0",
93
+ "tsup": "^8.0.2",
114
94
  "typescript": "^5.3.3"
115
95
  },
116
96
  "dependencies": {
117
- "@babel/runtime-corejs3": "^7.23.6",
118
97
  "use-ref-from": "^0.1.0",
119
- "use-state-with-ref": "^0.1.1-main.bf0fd65"
98
+ "use-state-with-ref": "^0.2.0-main.530523c"
120
99
  }
121
100
  }
@@ -1,2 +0,0 @@
1
- import useStateWithRef from './useStateWithRef';
2
- export { useStateWithRef };
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
- _Object$defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- _Object$defineProperty(exports, "useStateWithRef", {
9
- enumerable: true,
10
- get: function get() {
11
- return _useStateWithRef.default;
12
- }
13
- });
14
- var _useStateWithRef = _interopRequireDefault(require("./useStateWithRef"));
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_useStateWithRef","_interopRequireDefault","require"],"sources":["../../src/index.ts"],"sourcesContent":["import useStateWithRef from './useStateWithRef';\n\nexport { useStateWithRef };\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA"}
@@ -1,10 +0,0 @@
1
- import { type Dispatch, type SetStateAction } from 'react';
2
- import { useRefFrom } from 'use-ref-from';
3
- type ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;
4
- export default function useStateWithRef<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];
5
- export default function useStateWithRef<S = undefined>(): [
6
- S | undefined,
7
- Dispatch<SetStateAction<S | undefined>>,
8
- ReadonlyRefObject<S | undefined>
9
- ];
10
- export {};
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
5
- _Object$defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = useStateWithRef;
9
- var _freeze = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/freeze"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
11
- var _react = require("react");
12
- var _useRefFrom = require("use-ref-from");
13
- function useStateWithRef(initialState) {
14
- var _useState = (0, _react.useState)(initialState),
15
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
16
- value = _useState2[0],
17
- setter = _useState2[1];
18
- return (0, _freeze.default)([value, setter, (0, _useRefFrom.useRefFrom)(value)]);
19
- }
20
- //# sourceMappingURL=useStateWithRef.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStateWithRef.js","names":["_react","require","_useRefFrom","useStateWithRef","initialState","_useState","useState","_useState2","_slicedToArray2","default","value","setter","_freeze","useRefFrom"],"sources":["../../src/useStateWithRef.ts"],"sourcesContent":["import { type Dispatch, type SetStateAction, useState } from 'react';\nimport { useRefFrom } from 'use-ref-from';\n\ntype ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;\n\nexport default function useStateWithRef<S>(\n initialState: S | (() => S)\n): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];\n\nexport default function useStateWithRef<S = undefined>(): [\n S | undefined,\n Dispatch<SetStateAction<S | undefined>>,\n ReadonlyRefObject<S | undefined>\n];\n\nexport default function useStateWithRef<S>(\n initialState?: S | (() => S)\n): readonly [S | undefined, Dispatch<SetStateAction<S | undefined>>, ReadonlyRefObject<S | undefined>] {\n const [value, setter] = useState<S | undefined>(initialState);\n\n return Object.freeze([value, setter, useRefFrom(value)]);\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAce,SAASE,eAAeA,CACrCC,YAA4B,EACyE;EACrG,IAAAC,SAAA,GAAwB,IAAAC,eAAQ,EAAgBF,YAAY,CAAC;IAAAG,UAAA,OAAAC,eAAA,CAAAC,OAAA,EAAAJ,SAAA;IAAtDK,KAAK,GAAAH,UAAA;IAAEI,MAAM,GAAAJ,UAAA;EAEpB,OAAO,IAAAK,OAAA,CAAAH,OAAA,EAAc,CAACC,KAAK,EAAEC,MAAM,EAAE,IAAAE,sBAAU,EAACH,KAAK,CAAC,CAAC,CAAC;AAC1D"}
@@ -1,2 +0,0 @@
1
- import useStateWithRef from './useStateWithRef';
2
- export { useStateWithRef };
@@ -1,3 +0,0 @@
1
- import useStateWithRef from './useStateWithRef';
2
- export { useStateWithRef };
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["useStateWithRef"],"sources":["../../src/index.ts"],"sourcesContent":["import useStateWithRef from './useStateWithRef';\n\nexport { useStateWithRef };\n"],"mappings":"AAAA,OAAOA,eAAe,MAAM,mBAAmB;AAE/C,SAASA,eAAe"}
@@ -1,10 +0,0 @@
1
- import { type Dispatch, type SetStateAction } from 'react';
2
- import { useRefFrom } from 'use-ref-from';
3
- type ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;
4
- export default function useStateWithRef<S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];
5
- export default function useStateWithRef<S = undefined>(): [
6
- S | undefined,
7
- Dispatch<SetStateAction<S | undefined>>,
8
- ReadonlyRefObject<S | undefined>
9
- ];
10
- export {};
@@ -1,12 +0,0 @@
1
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
2
- import _Object$freeze from "@babel/runtime-corejs3/core-js-stable/object/freeze";
3
- import { useState } from 'react';
4
- import { useRefFrom } from 'use-ref-from';
5
- export default function useStateWithRef(initialState) {
6
- var _useState = useState(initialState),
7
- _useState2 = _slicedToArray(_useState, 2),
8
- value = _useState2[0],
9
- setter = _useState2[1];
10
- return _Object$freeze([value, setter, useRefFrom(value)]);
11
- }
12
- //# sourceMappingURL=useStateWithRef.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useStateWithRef.js","names":["useState","useRefFrom","useStateWithRef","initialState","_useState","_useState2","_slicedToArray","value","setter","_Object$freeze"],"sources":["../../src/useStateWithRef.ts"],"sourcesContent":["import { type Dispatch, type SetStateAction, useState } from 'react';\nimport { useRefFrom } from 'use-ref-from';\n\ntype ReadonlyRefObject<S> = ReturnType<typeof useRefFrom<S>>;\n\nexport default function useStateWithRef<S>(\n initialState: S | (() => S)\n): [S, Dispatch<SetStateAction<S>>, ReadonlyRefObject<S>];\n\nexport default function useStateWithRef<S = undefined>(): [\n S | undefined,\n Dispatch<SetStateAction<S | undefined>>,\n ReadonlyRefObject<S | undefined>\n];\n\nexport default function useStateWithRef<S>(\n initialState?: S | (() => S)\n): readonly [S | undefined, Dispatch<SetStateAction<S | undefined>>, ReadonlyRefObject<S | undefined>] {\n const [value, setter] = useState<S | undefined>(initialState);\n\n return Object.freeze([value, setter, useRefFrom(value)]);\n}\n"],"mappings":";;AAAA,SAA6CA,QAAQ,QAAQ,OAAO;AACpE,SAASC,UAAU,QAAQ,cAAc;AAczC,eAAe,SAASC,eAAeA,CACrCC,YAA4B,EACyE;EACrG,IAAAC,SAAA,GAAwBJ,QAAQ,CAAgBG,YAAY,CAAC;IAAAE,UAAA,GAAAC,cAAA,CAAAF,SAAA;IAAtDG,KAAK,GAAAF,UAAA;IAAEG,MAAM,GAAAH,UAAA;EAEpB,OAAOI,cAAA,CAAc,CAACF,KAAK,EAAEC,MAAM,EAAEP,UAAU,CAACM,KAAK,CAAC,CAAC,CAAC;AAC1D"}