
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
@fly4react/observer
Advanced tools
📖 中文文档: 查看中文版本
npm install @fly4react/observer
# or
yarn add @fly4react/observer
# or
pnpm add @fly4react/observer
import { useIntersectionObserver } from '@fly4react/observer';
function MyComponent() {
const [ref, inView] = useIntersectionObserver({
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
});
return (
<div ref={ref}>
{inView ? 'Element is visible!' : 'Element is not visible'}
</div>
);
}
A hook for observing element intersection with viewport.
const [ref, inView, entry] = useIntersectionObserver(options, deps);
Parameters:
options: IntersectionObserver optionsdeps: Dependency array for memoizationReturns:
ref: Ref to attach to target elementinView: Boolean indicating if element is in viewentry: IntersectionObserverEntry objectA hook for detecting if element is in viewport.
const [ref, inView] = useInViewport(options);
A hook for tracking element position.
const [ref, position] = useElementPosition(options);
A hook for tracking element position without triggering re-renders.
const ref = useRef<HTMLDivElement>(null);
const positionRef = useElementPositionRef(ref, options);
// Access position data
const handleClick = () => {
if (positionRef.current) {
console.log('Position:', positionRef.current.boundingClientRect);
}
};
A lazy version of useElementPositionRef that only calculates position when explicitly requested.
const ref = useRef<HTMLDivElement>(null);
const getPosition = useLazyElementPositionRef(ref, options);
// Get position on demand
const handleClick = () => {
const position = getPosition();
if (position) {
console.log('Position:', position.boundingClientRect);
}
};
A hook for detecting scroll direction.
const scrollDirection = useScrollDirection();
import { useIntersectionObserver } from '@fly4react/observer';
function LazyImage({ src, alt }) {
const [ref, inView] = useIntersectionObserver({
threshold: 0.1,
triggerOnce: true
});
return (
<div ref={ref}>
{inView ? (
<img src={src} alt={alt} />
) : (
<div className="placeholder">Loading...</div>
)}
</div>
);
}
import { useElementPosition } from '@fly4react/observer';
function ScrollIndicator() {
const [ref, position] = useElementPosition();
return (
<div>
<div ref={ref}>Content</div>
<div>Position: {position.ratio}</div>
</div>
);
}
import { useLazyElementPositionRef } from '@fly4react/observer';
function LazyScrollIndicator() {
const ref = useRef<HTMLDivElement>(null);
const getPosition = useLazyElementPositionRef(ref);
const handleClick = () => {
const position = getPosition();
if (position) {
console.log('Current position:', position.boundingClientRect);
console.log('Intersection ratio:', position.intersectionRatio);
}
};
return (
<div>
<div ref={ref}>Content</div>
<button onClick={handleClick}>Get Position</button>
</div>
);
}
import { useIntersectionObserver } from '@fly4react/observer';
function AnimatedElement() {
const [ref, inView] = useIntersectionObserver({
threshold: 0.5
});
return (
<div
ref={ref}
className={`fade-in ${inView ? 'visible' : ''}`}
>
Animated content
</div>
);
}
MIT
FAQs
一个基于 Intersection Observer API 的现代 React 工具库,提供懒加载、可见性检测、位置跟踪和滚动方向检测功能
The npm package @fly4react/observer receives a total of 14 weekly downloads. As such, @fly4react/observer popularity was classified as not popular.
We found that @fly4react/observer demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.