first commit
This commit is contained in:
38
node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.mjs
generated
vendored
Normal file
38
node_modules/framer-motion/dist/es/motion/utils/use-motion-ref.mjs
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use client";
|
||||
import { useCallback } from 'react';
|
||||
import { isRefObject } from '../../utils/is-ref-object.mjs';
|
||||
|
||||
/**
|
||||
* Creates a ref function that, when called, hydrates the provided
|
||||
* external ref and VisualElement.
|
||||
*/
|
||||
function useMotionRef(visualState, visualElement, externalRef) {
|
||||
return useCallback((instance) => {
|
||||
if (instance) {
|
||||
visualState.onMount && visualState.onMount(instance);
|
||||
}
|
||||
if (visualElement) {
|
||||
if (instance) {
|
||||
visualElement.mount(instance);
|
||||
}
|
||||
else {
|
||||
visualElement.unmount();
|
||||
}
|
||||
}
|
||||
if (externalRef) {
|
||||
if (typeof externalRef === "function") {
|
||||
externalRef(instance);
|
||||
}
|
||||
else if (isRefObject(externalRef)) {
|
||||
externalRef.current = instance;
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Include externalRef in dependencies to ensure the callback updates
|
||||
* when the ref changes, allowing proper ref forwarding.
|
||||
*/
|
||||
[visualElement]);
|
||||
}
|
||||
|
||||
export { useMotionRef };
|
||||
Reference in New Issue
Block a user