Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
IntersectionObserver.unobserve() no funciona en useEffect

Estoy usando el observador de intersección para usar un desvanecimiento en la animación una vez, al principio estaba usando el observador de intersección de reacción, pero no sabía cómo usar el gancho personalizado no observado e intentaba hacer un contador de animación para activar solo la animación. una vez no funcionó.

Volver al observador de intersección normal en un useEffect se ve así:

 const aboutRef = useRef(); const [elementIsVisible, setElementIsVisible] = useState(); useEffect(() => { const observer = new IntersectionObserver((entries) => { const entry = entries[0]; setElementIsVisible(entry.isIntersecting); }); observer.observe(aboutRef.current); }, []);
 <section className="about" id="about" ref={aboutRef}> <div className={`styled-text ${ elementIsVisible ? "styled-text-animation" : "" }`} > </div> <div className={`styled-pic ${ elementIsVisible ? "styled-pic-animation" : "" }`} > </div> </section>

Intenté usar unobserve así:

 useEffect(() => { const observer = new IntersectionObserver((entries) => { const entry = entries[0]; setElementIsVisible(entry.isIntersecting); }); observer.observe(aboutRef.current); if (setElementIsVisible) { observer.unobserve(aboutRef.current); } }, []);

Como esto:

 useEffect(() => { const observer = new IntersectionObserver((entries) => { const entry = entries[0]; setElementIsVisible(entry.isIntersecting); }); observer.observe(aboutRef.current); observer.unobserve(aboutRef.current); }, []);

Y así:

 useEffect(() => { const observer = new IntersectionObserver((entries) => { const entry = entries[0]; setElementIsVisible(entry.isIntersecting); }); observer.observe(aboutRef.current); }, []); useEffect(() => { const observer = new IntersectionObserver((entries) => { observer.unobserve(aboutRef); }); }, [elementIsVisible]);

Y ambos no funcionaron, ¿cuál es la manera de hacer esto? O use unobserve con react-intersection-observer

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!