Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
how to detect the scroll reaches the specific component in react js using ref

how can we identify onScoll event reaches a specific component? I have tried to use ref to scrollinto view thats works when we fire click event. But how it works user scroll down and reaches specific component, that time i should perform some task. how can we achive that?

 import "./styles.css";
import { useRef, useEffect } from "react";
export default function App() {
  const eipCard = useRef(null);
  const salaryCard = useRef(null);
  const salesCard = useRef(null);

  const handleStickyHeader = () => {
     //handle logic

    // should trigger scroll reaches eip card
    console.log("reaches eip card")
    // should trigger scroll reaches salary card
    console.log("reaches salary card")
    // should trigger scroll reaches sales card
    console.log("reaches sales card")
  };

  useEffect(() => {
    if (typeof window !== "undefined") {
      window.addEventListener("scroll", handleStickyHeader);
    }
    return () => window.removeEventListener("scroll", handleStickyHeader);
  }, []);

  return (
    <div className="App">
      <div
        ref={eipCard}
        style={{ height: "500px", backgroundColor: "red" }}
      ></div>
      <div
        ref={salaryCard}
        style={{ height: "500px", backgroundColor: "blue" }}
      ></div>
      <div
        ref={salesCard}
        style={{ height: "500px", backgroundColor: "blue" }}
      ></div>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use Intersection Observer API to create custom React hooks checking components in view. Here is the working Example

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda