Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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.
enabled: boolean
Enables/disables running the viewport-check side effect.
Default: true
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetLeft?: number
Number of pixels to add to the left of the area checked against when computing in view elements.
Default: 0
offsetRight?: number
Number of pixels to add to the right 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.
enabled: boolean
Enables/disables running the viewport-check side effect.
Default: true
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetLeft?: number
Number of pixels to add to the left of the area checked against when computing in view elements.
Default: 0
offsetRight?: number
Number of pixels to add to the right 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.
enabled: boolean
Enables/disables running the viewport-check side effect.
Default: true
offsetBottom?: number
Number of pixels to add to the bottom of the area checked against when computing in view elements.
Default: 0
offsetLeft?: number
Number of pixels to add to the left of the area checked against when computing in view elements.
Default: 0
offsetRight?: number
Number of pixels to add to the right 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
offsetBottom
/offsetLeft
/offsetRight
/offsetTop
to be -1
.rootMargin
in iframe contexts, which means that
offsets will be ignored.
FAQs
React hooks for monitoring an element's intersection with the viewport
The npm package react-peekaboo receives a total of 2,524 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 uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.