Skip to content

Instantly share code, notes, and snippets.

View ali-sabry's full-sized avatar
💥
Creating new repos

Ali Sabry ali-sabry

💥
Creating new repos
View GitHub Profile
@ali-sabry
ali-sabry / IntersectionObserver.js
Last active April 5, 2023 04:48
The useIntersectionObserver react custom Hook enables detection of an element's visibility on the screen, allowing for lazy loading of content like images, improving page load times and performance.
//=== Craete The Custom Hook
import { useState, useEffect } from 'react';
const useIntersectionObserver = (ref, options) => {
const [isIntersecting, setIsIntersecting] = useState(false);
useEffect(() => {
const observer = new IntersectionObserver(([entry]) => {
setIsIntersecting(entry.isIntersecting);
}, options);