pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+1
View File
@@ -0,0 +1 @@
export { default } from './useForkRef';
+1
View File
@@ -0,0 +1 @@
export { default } from './useForkRef';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/useForkRef/index.js",
"types": "./index.d.ts"
}
+2
View File
@@ -0,0 +1,2 @@
import * as React from 'react';
export default function useForkRef<Instance>(...refs: Array<React.Ref<Instance> | undefined>): React.RefCallback<Instance> | null;
+22
View File
@@ -0,0 +1,22 @@
'use client';
import * as React from 'react';
import setRef from '../setRef';
export default function useForkRef(...refs) {
/**
* This will create a new function if the refs passed to this hook change and are all defined.
* This means react will call the old forkRef with `null` and the new forkRef
* with the ref. Cleanup naturally emerges from this behavior.
*/
return React.useMemo(() => {
if (refs.every(ref => ref == null)) {
return null;
}
return instance => {
refs.forEach(ref => {
setRef(ref, instance);
});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, refs);
}