Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
react-peekaboo
Advanced tools
React hooks for monitoring an element's intersection with the viewport
react-peekaboo
React hooks for monitoring an element's intersection with the viewport.
npm install react-peekaboo
import React, { useState } from 'react';
import { useIntersecting, useIntersectionChange } from 'react-peekaboo';
function UseIntersectionExample() {
let [ref, isIntersecting] = useIntersecting<HTMLDivElement>();
return (
<div ref={ref}>I am {isIntersecting ? 'visible' : 'not visible'}.</div>
);
}
function UseIntersectionChangeExample() {
let [isIntersecting, onChange] = useState<boolean>(false);
let ref = useIntersectionChange<HTMLDivElement>(onChange);
return (
<div ref={ref}>I am {isIntersecting ? 'visible' : 'not visible'}.</div>
);
}
All functions accept a common set of options:
enabled?: boolean
: Enables/disables running the side effect that calculates
the element's intersection status. (default: true
)
offsetBottom?: number
: Number of pixels to add to the bottom of the area
checked against when computing element intersection. (default: 0
)
offsetLeft?: number
: Number of pixels to add to the left of the area checked
against when computing element intersection. (default: 0
)
offsetRight?: number
: Number of pixels to add to the right of the area
checked against when computing element intersection. (default: 0
)
offsetTop?: number
: Number of pixels to add to the top of the area checked
against when computing element intersection. (default: 0
)
throttle?: number
: Number of ms to throttle scroll events (only applies in
environments that don't support IntersectionObserver or when using
useScrollIntersection
/useScrollIntersectionChangeCallback
). (default:
100
)
useIntersecting
Type: (options: Options) => [RefCallback, boolean]
Returns a ref and the element's intersection status using IntersectionObserver
or scroll
/resize
event listeners and getBoundingClientRect
in unsupported
environments.
The ref returned must be attached to a DOM node.
useIntersectionChange
Type:
(onChange: (isIntersecting: boolean) => void, options: Options) => RefCallback;
Runs a callback that receives the element's intersection status each time it
changes using IntersectionObserver or scroll
/resize
event listeners and
getBoundingClientRect
in unsupported environments.
Returns a ref that must be attached to a DOM node.
usePeekaboo
Type:
type SetupHandler = (
element: HTMLElement,
onChange: (isIntersecting: boolean) => void,
options?: Options,
) => TeardownHandler;
(
setup: SetupHandler,
onChange: (isIntersecting: boolean) => void,
options?: Options,
) => RefCallback;
Uses setup
to run onChange
when the element's intersection status changes.
You can pass scroll
, io
, or peekaboo
from dom-peekaboo
or implement our
own setup function.
FAQs
React hooks for monitoring an element's intersection with the viewport
The npm package react-peekaboo receives a total of 4,115 weekly downloads. As such, react-peekaboo popularity was classified as popular.
We found that react-peekaboo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.