use-state-with-ref 0.0.0-main.ab7b671
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 +127 -0
- package/lib/commonjs/index.js +15 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/useStateWithRef.js +20 -0
- package/lib/commonjs/useStateWithRef.js.map +1 -0
- package/lib/commonjs-types/index.d.ts +2 -0
- package/lib/commonjs-types/useStateWithRef.d.ts +10 -0
- package/lib/esmodules/index.js +3 -0
- package/lib/esmodules/index.js.map +1 -0
- package/lib/esmodules/useStateWithRef.js +12 -0
- package/lib/esmodules/useStateWithRef.js.map +1 -0
- package/lib/esmodules-types/index.d.ts +2 -0
- package/lib/esmodules-types/useStateWithRef.d.ts +10 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 William Wong
|
|
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,127 @@
|
|
|
1
|
+
# `use-state-with-ref`
|
|
2
|
+
|
|
3
|
+
React `useState` with a readonly `RefObject`.
|
|
4
|
+
|
|
5
|
+
## Background
|
|
6
|
+
|
|
7
|
+
Components often detect changes of props to check if the component need to be re-rendered. If the function is changed, the component should be re-rendered. To optimize performance, unnecessary changes should be removed.
|
|
8
|
+
|
|
9
|
+
For example, unless there is an intentional change, the return value of `useCallback` should be kept the same across the lifetime of the component.
|
|
10
|
+
|
|
11
|
+
`useStateWithRef` call `useState` and appending a readonly `RefObject`. The `RefObject` can be used in `useCallback` to minimize function changes.
|
|
12
|
+
|
|
13
|
+
## How to use
|
|
14
|
+
|
|
15
|
+
### Before optimization
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
const MyComponent = ({ onSubmit }) => {
|
|
19
|
+
const [value, setValue] = useState();
|
|
20
|
+
|
|
21
|
+
// This callback will be recreated every time <MyComponent> is rendered.
|
|
22
|
+
const handleInput = ({ currentTarget: { value } }) => setValue(value);
|
|
23
|
+
|
|
24
|
+
// This callback will be recreated every time <MyComponent> is rendered.
|
|
25
|
+
const handleSubmit = () => onSubmit.current(valueRef.current);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
// <form> will be re-rendered every time <MyComponent> is rendered.
|
|
29
|
+
<form onSubmit={handleSubmit}>
|
|
30
|
+
<input onInput={handleInput} type="text" value={value} />
|
|
31
|
+
</form>
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Optimization without `useStateWithRef`
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
const MyComponent = ({ onSubmit }) => {
|
|
40
|
+
const [value, setValue] = useState();
|
|
41
|
+
const onSubmitRef = useRefFrom(onSubmit);
|
|
42
|
+
const valueRef = useRef();
|
|
43
|
+
|
|
44
|
+
valueRef.current = value;
|
|
45
|
+
|
|
46
|
+
// This callback will never change across the lifetime of <MyComponent> because `setValue` never change.
|
|
47
|
+
const handleInput = useCallback(({ currentTarget: { value } }) => setValue(value), [setValue]);
|
|
48
|
+
|
|
49
|
+
// This callback will never change across the lifetime of <MyComponent> because `onSubmitRef` and `valueRef` never change.
|
|
50
|
+
const handleSubmit = useCallback(() => onSubmitRef.current(valueRef.current), [onSubmitRef, valueRef]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
// <form> will never re-render across the lifetime of <MyComponent>.
|
|
54
|
+
<form onSubmit={handleSubmit}>
|
|
55
|
+
<input onInput={handleInput} type="text" value={value} />
|
|
56
|
+
</form>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Optimization with `useStateWithRef`
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
const MyComponent = ({ onSubmit }) => {
|
|
65
|
+
const [value, setValue, valueRef] = useStateWithRef();
|
|
66
|
+
const onSubmitRef = useRefFrom(onSubmit);
|
|
67
|
+
|
|
68
|
+
// This callback will never change across the lifetime of <MyComponent> because `setValue` never change.
|
|
69
|
+
const handleInput = useCallback(({ currentTarget: { value } }) => setValue(value), [setValue]);
|
|
70
|
+
|
|
71
|
+
// This callback will never change across the lifetime of <MyComponent> because `onSubmitRef` and `valueRef` never change.
|
|
72
|
+
const handleSubmit = useCallback(() => onSubmitRef.current(valueRef.current), [onSubmitRef, valueRef]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
// <form> will never re-render across the lifetime of <MyComponent>.
|
|
76
|
+
<form onSubmit={handleSubmit}>
|
|
77
|
+
<input onInput={handleInput} type="text" value={value} />
|
|
78
|
+
</form>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
export default function useStateWithRef<S>(
|
|
87
|
+
initialState: S | (() => S)
|
|
88
|
+
): [
|
|
89
|
+
S,
|
|
90
|
+
Dispatch<SetStateAction<S>>,
|
|
91
|
+
ReadonlyRefObject<S>
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
export default function useStateWithRef<S = undefined>(): [
|
|
95
|
+
S | undefined,
|
|
96
|
+
Dispatch<SetStateAction<S | undefined>>,
|
|
97
|
+
ReadonlyRefObject<S | undefined>
|
|
98
|
+
];
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Behaviors
|
|
102
|
+
|
|
103
|
+
### Why should I use `RefObject` to optimize performance?
|
|
104
|
+
|
|
105
|
+
When a prop change, a component will need to be re-rendered. This propagation amplifies when passing unchanged props to a large component. Thus, [`memo()`](https://react.dev/reference/react/memo) (a.k.a. [pure component](https://react.dev/reference/react/PureComponent)) helps prevent rendering when no props changed.
|
|
106
|
+
|
|
107
|
+
[Pure components](https://react.dev/learn/keeping-components-pure) are components which will only re-render when there is any props changed.
|
|
108
|
+
|
|
109
|
+
Generally, when any `onXXX` callback prop is changed, in most cases, the component should not need to be re-rendered because the callback props may not cause a visual change. In other words, changing `onXXX` will re-render but there will be no visual change (a.k.a. a wasted render).
|
|
110
|
+
|
|
111
|
+
As props are changed, `memo()` and `PureComponent` could not prevent the wasted render.
|
|
112
|
+
|
|
113
|
+
Despite `arePropsEqual` and `shouldComponentUpdate` can be used to ignore `onXXX` changes, a bad implementation could easily cause UI issues. Also, some callback functions may have legitimate reasons to cause a re-render. For example, in Fluent UI, changing the `IRenderFunction` should re-render because rows of a `<DetailsList>` could be rendered differently. Thus, `arePropsEqual` and `shouldComponentUpdate` are not generally recommended to use unless in very limited case.
|
|
114
|
+
|
|
115
|
+
The most effective way to prevent wasted render is to follow [React best practices on pure rendering logic](https://react.dev/learn/keeping-components-pure), make sure all props are immutable and only change them when there is a visual change.
|
|
116
|
+
|
|
117
|
+
#### Seriously?
|
|
118
|
+
|
|
119
|
+
Let's look at [`useSyncExternalStore()`](https://react.dev/reference/react/useSyncExternalStore). When the `subscribe()` callback is changed, the `useSyncExternalStore()` hook will re-subscribe. Callback functions should be properly memoized and only change when needed. Otherwise, in `useSyncExternalStore()` case, every re-render will resubscribe again.
|
|
120
|
+
|
|
121
|
+
## Contributions
|
|
122
|
+
|
|
123
|
+
Like us? [Star](https://github.com/compulim/use-state-with-ref/stargazers) us.
|
|
124
|
+
|
|
125
|
+
Want to make it better? [File](https://github.com/compulim/use-state-with-ref/issues) us an issue.
|
|
126
|
+
|
|
127
|
+
Don't like something you see? [Submit](https://github.com/compulim/use-state-with-ref/pulls) a pull request.
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 {};
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "use-state-with-ref",
|
|
3
|
+
"version": "0.0.0-main.ab7b671",
|
|
4
|
+
"description": "React `useState` with a readonly `RefObject`.",
|
|
5
|
+
"files": [
|
|
6
|
+
"./lib/"
|
|
7
|
+
],
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./lib/esmodules-types/index.d.ts",
|
|
12
|
+
"default": "./lib/esmodules/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./lib/commonjs-types/index.d.ts",
|
|
16
|
+
"default": "./lib/commonjs/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./useStateWithRef": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./lib/esmodules-types/useStateWithRef.d.ts",
|
|
22
|
+
"default": "./lib/esmodules/useStateWithRef.js"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./lib/commonjs-types/useStateWithRef.d.ts",
|
|
26
|
+
"default": "./lib/commonjs/useStateWithRef.js"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./lib/commonjs/index.js",
|
|
31
|
+
"typings": "./lib/commonjs-types/index.d.ts",
|
|
32
|
+
"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",
|
|
39
|
+
"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",
|
|
46
|
+
"precommit": "npm run precommit:eslint && npm run precommit:typescript:production && npm run precommit:typescript:test",
|
|
47
|
+
"precommit:eslint": "eslint ./src/",
|
|
48
|
+
"precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
|
|
49
|
+
"precommit:typescript:test": "tsc --noEmit --project ./src/tsconfig.precommit.test.json",
|
|
50
|
+
"prepack": "cp ../../CHANGELOG.md . && cp ../../LICENSE . && cp ../../README.md .",
|
|
51
|
+
"start": "esbuild --bundle --outfile=./public/main.js --servedir=./public --sourcemap ./scenarios/index.jsx",
|
|
52
|
+
"test": "jest"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/compulim/use-state-with-ref.git"
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"react",
|
|
60
|
+
"react-hook",
|
|
61
|
+
"react-hooks"
|
|
62
|
+
],
|
|
63
|
+
"author": "William Wong (https://github.com/compulim)",
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/compulim/use-state-with-ref/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/compulim/use-state-with-ref#readme",
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"react": ">=16.9.0"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@babel/cli": "^7.22.15",
|
|
74
|
+
"@babel/core": "^7.22.17",
|
|
75
|
+
"@babel/plugin-transform-runtime": "^7.22.15",
|
|
76
|
+
"@babel/preset-env": "^7.22.15",
|
|
77
|
+
"@babel/preset-react": "^7.22.15",
|
|
78
|
+
"@babel/preset-typescript": "^7.22.15",
|
|
79
|
+
"@testing-library/react": "^14.0.0",
|
|
80
|
+
"@tsconfig/recommended": "^1.0.2",
|
|
81
|
+
"@tsconfig/strictest": "^2.0.2",
|
|
82
|
+
"@types/jest": "^29.5.4",
|
|
83
|
+
"@types/react": "^18.2.21",
|
|
84
|
+
"jest": "^29.6.4",
|
|
85
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
86
|
+
"react": "^18.2.0",
|
|
87
|
+
"react-test-renderer": "^18.2.0",
|
|
88
|
+
"typescript": "^5.2.2"
|
|
89
|
+
},
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"@babel/runtime-corejs3": "^7.22.15",
|
|
92
|
+
"use-ref-from": "^0.0.2",
|
|
93
|
+
"use-state-with-ref": "^0.0.0-main.ab7b671"
|
|
94
|
+
}
|
|
95
|
+
}
|