@reactuses/core 5.0.15 → 5.0.17
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 +21 -8
- package/dist/index-client-DJgtg2U_.cjs +30 -0
- package/dist/index-client-Qon46B4S.js +28 -0
- package/dist/index.cjs +375 -338
- package/dist/index.d.cts +141 -95
- package/dist/index.d.mts +141 -95
- package/dist/index.d.ts +141 -95
- package/dist/index.mjs +372 -340
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -30,19 +30,19 @@ Collection of essential React Hooks Utilities.
|
|
|
30
30
|
## QuickStart
|
|
31
31
|
|
|
32
32
|
```tsx harmony
|
|
33
|
-
import { useToggle } from
|
|
33
|
+
import { useToggle } from '@reactuses/core'
|
|
34
34
|
|
|
35
35
|
function Demo() {
|
|
36
|
-
const [on, toggle] = useToggle(true)
|
|
36
|
+
const [on, toggle] = useToggle(true)
|
|
37
37
|
|
|
38
38
|
return (
|
|
39
39
|
<div>
|
|
40
|
-
<div>{on ?
|
|
40
|
+
<div>{on ? 'ON' : 'OFF'}</div>
|
|
41
41
|
<button onClick={toggle}>Toggle</button>
|
|
42
42
|
<button onClick={() => toggle(true)}>set ON</button>
|
|
43
43
|
<button onClick={() => toggle(false)}>set OFF</button>
|
|
44
44
|
</div>
|
|
45
|
-
)
|
|
45
|
+
)
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -52,10 +52,23 @@ Refer to [documentations](https://reactuse.com/) for more details.
|
|
|
52
52
|
|
|
53
53
|
## Documentation & Live Examples
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
- [Documentation](https://reactuse.com/)
|
|
56
56
|
|
|
57
57
|
<hr/>
|
|
58
58
|
|
|
59
|
+
## Sponsor Me
|
|
60
|
+
|
|
61
|
+
If my work has helped you, consider buying me a cup of coffee. Thank you very much🥰!.
|
|
62
|
+
|
|
63
|
+
[Buy me a coffee](https://www.buymeacoffee.com/lianwenwu)
|
|
64
|
+
|
|
65
|
+
### For Chinese User
|
|
66
|
+
|
|
67
|
+
<p float="left">
|
|
68
|
+
<img src="https://d21002cb.images-f3o.pages.dev/images/wechat.jpg" alt="Wechat Pay" width="200" />
|
|
69
|
+
<img src="https://d21002cb.images-f3o.pages.dev/images/ali.jpg" alt="Ali Pay" width="200" />
|
|
70
|
+
</p>
|
|
71
|
+
|
|
59
72
|
## Feedback
|
|
60
73
|
|
|
61
74
|
You can submit an [issue](https://github.com/childrentime/reactuse/issues) or provide feedback on [Discord](https://discord.gg/HMsq6cFkKp).
|
|
@@ -76,8 +89,8 @@ See the [**ChangeLog**](https://github.com/childrentime/reactuse/blob/main/packa
|
|
|
76
89
|
|
|
77
90
|
This project is heavily inspired by the following awesome projects.
|
|
78
91
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
92
|
+
- [streamich/react-use](https://github.com/streamich/react-use)
|
|
93
|
+
- [ahooks](https://github.com/alibaba/hooks)
|
|
94
|
+
- [vueuse](https://github.com/vueuse/vueuse)
|
|
82
95
|
|
|
83
96
|
<hr/>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var React = require('react');
|
|
3
|
+
|
|
4
|
+
function assignRef(ref, value) {
|
|
5
|
+
if (ref == null) return;
|
|
6
|
+
if (typeof ref === 'function') {
|
|
7
|
+
ref(value);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
ref.current = value;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function mergeRefs(...refs) {
|
|
17
|
+
return (node)=>{
|
|
18
|
+
refs.forEach((ref)=>{
|
|
19
|
+
assignRef(ref, node);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function useMergedRefs(...refs) {
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
return React.useMemo(()=>mergeRefs(...refs), refs);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.assignRef = assignRef;
|
|
29
|
+
exports.mergeRefs = mergeRefs;
|
|
30
|
+
exports.useMergedRefs = useMergedRefs;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
function assignRef(ref, value) {
|
|
5
|
+
if (ref == null) return;
|
|
6
|
+
if (typeof ref === 'function') {
|
|
7
|
+
ref(value);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
ref.current = value;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function mergeRefs(...refs) {
|
|
17
|
+
return (node)=>{
|
|
18
|
+
refs.forEach((ref)=>{
|
|
19
|
+
assignRef(ref, node);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function useMergedRefs(...refs) {
|
|
24
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
|
+
return useMemo(()=>mergeRefs(...refs), refs);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { assignRef as a, mergeRefs as m, useMergedRefs as u };
|