first commit
This commit is contained in:
16
hooks/use-is-in-view.jsx
Normal file
16
hooks/use-is-in-view.jsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
import { useInView } from 'motion/react';
|
||||
|
||||
function useIsInView(ref, options = {}) {
|
||||
const { inView, inViewOnce = false, inViewMargin = '0px' } = options;
|
||||
const localRef = React.useRef(null);
|
||||
React.useImperativeHandle(ref, () => localRef.current);
|
||||
const inViewResult = useInView(localRef, {
|
||||
once: inViewOnce,
|
||||
margin: inViewMargin,
|
||||
});
|
||||
const isInView = !inView || inViewResult;
|
||||
return { ref: localRef, isInView };
|
||||
}
|
||||
|
||||
export { useIsInView };
|
||||
Reference in New Issue
Block a user