useIsInView
unlumen-ui/hooks-use-is-in-viewFreeHook
A hook that allows you to check if an element is in view.
Live preview
live · rendered by the registry
Rendered by Unlumen Ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.unlumen.com/r/hooks-use-is-in-view.jsonSource
1import * as React from "react";2import { useInView, type UseInViewOptions } from "motion/react";34interface UseIsInViewOptions {5 inView?: boolean;6 inViewOnce?: boolean;7 inViewMargin?: UseInViewOptions["margin"];8}910function useIsInView<T extends HTMLElement = HTMLElement>(11 ref: React.Ref<T>,12 options: UseIsInViewOptions = {},13) {14 const { inView, inViewOnce = false, inViewMargin = "0px" } = options;15 const localRef = React.useRef<T>(null);16 React.useImperativeHandle(ref, () => localRef.current as T);17 const inViewResult = useInView(localRef, {18 once: inViewOnce,19 margin: inViewMargin,20 });21 const isInView = !inView || inViewResult;22 return { ref: localRef, isInView };23}2425export { useIsInView, type UseIsInViewOptions };
What it pulls in
npm packages
Files it writes
More from Unlumen Ui
All 225 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| useAutoHeighthooks-use-auto-height | Unlumen Ui | Hooks | Free | no deps | |
| Use Controlled Statehooks-use-controlled-state | Unlumen Ui | Hooks | Free | no deps | |
| useDataStatehooks-use-data-state | Unlumen Ui | Hooks | Free | no deps | |
| useMotionValueStatehooks-use-motion-value-state | Unlumen Ui | Hooks | Free | 1 dep |
