Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
react-peekaboo
Advanced tools
React component that notifies when its child enters or exits the viewport
react-peekaboo
React component that notifies you when its child enters or exits the viewport.
Under the hood, it uses the IntersectionObserver
API in supported environments
and falls back to listening for scroll
and resize
events in combination with
getBoundingClientRect
in unsupported environments.
yarn add react-peekaboo
Or
npm install --save react-peekaboo
import React, { useState } from 'react';
import { InView } from 'react-peekaboo';
function Example() {
const [isInViewport, setIsInViewport] = useState(false);
return (
<InView onChange={setIsInViewport}>
{ref => (
<div ref={ref}>I am {isInViewport ? 'visible' : 'not visible'}.</div>
)}
</InView>
);
}
InView
children: (ref: React.Ref<any>) => JSX.Element
Render prop that accepts a ref as its parameter. You must apply the ref to a DOM element.
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetTop?: number
Number of pixels to add to the top of the area checked against when computing in view elements.
Default: 0
onChange: (isInviewPort: boolean) => void
Callback that's invoked each time the wrapped element enters or exits the viewport.
throttle?: number
Number of ms to throttle scroll events (only applies in environments that don't support IntersectionObserver).
Default: 100
IO
children: (ref: React.Ref<any>) => JSX.Element
Render prop that accepts a ref as its parameter. You must apply the ref to a DOM element.
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetTop?: number
Number of pixels to add to the top of the area checked against when computing in view elements.
Default: 0
onChange: (isInviewPort: boolean) => void
Callback that's invoked each time the wrapped element enters or exits the viewport.
Scroll
children: (ref: React.Ref<any>) => JSX.Element
Render prop that accepts a ref as its parameter. You must apply the ref to a DOM element.
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetTop?: number
Number of pixels to add to the top of the area checked against when computing in view elements.
Default: 0
onChange: (isInviewPort: boolean) => void
Callback that's invoked each time the wrapped element enters or exits the viewport.
throttle?: number
Number of ms to throttle scroll events.
Default: 100
offsetTop
/offsetBottom
to be -1
.rootMargin
in iframe contexts, which means that
offsetTop
and offsetBottom
will be ignored.
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.
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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.