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

139
Views
¿Cómo paso el valor "isVisibility" como accesorio a otro componente (Reaccionar)

Quiero pasar el valor de isVisibile al componente "Livechat.js" para poder editar dinámicamente alguna información allí de acuerdo con el valor de isVisibile.

Archivo donde está la lógica isVisibile - NewsLetter.js

 const NewsLetter = () => { const newsLetterRef = useRef(); const [isVisible , setIsVisible] = useState() useEffect( () => { const observer = new IntersectionObserver( (entries) => { const entry = entries[0]; setIsVisible(entry.isIntersecting) }) observer.observe(newsLetterRef.current) } , []) return ( <> <NewsLetterWrapper> <div ref={newsLetterRef} className={styles.newsLetterCenter}> <div className={styles.newsLetterContainer}> <div> <p className={styles.newsLetterTitle}>Subscribe To Our <br /> <span> Newsletter For 10% - 50% OFF </span> </p> <p className={styles.newsLetterDesc}>Stay up to date with our latest offers and promotions by signing up now! <br /> Be the first to know of our 10% - 50% discounts.</p> </div> <div className={styles.newsLetterInputContent}> <div> <input className={styles.newsLetterInput} type="text" placeholder='Enter email' /> </div> <PrimaryButton> Submit </PrimaryButton> </div> </div> </div> </NewsLetterWrapper> </> ) } export default NewsLetter

Donde quiero usar el accesorio - Live.js

 const Livechat = (props) => { return ( <> <div className={styles.whatsappFloat}> <div className={styles.chatText}> <p>Chat With Us Now</p> </div> <a href='https://api.whatsapp.com/send?phone=000000000' > <img src={LivechatImg} alt= "/" /> </a> </div> </> ) }

Donde uso ambos componentes en una página - Homepage.js

 const HomePage = () => { return ( <> <Livechat /> <NewsLetter /> </>

Básicamente, lo que quiero hacer es obtener el valor isVisibile de NewsLetter y pasarlo como accesorio al componente Livechat. ¿Alguna idea de cómo se supone que debo lograr esto? Cualquier ayuda sería apreciada, gracias de antemano.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Recomendaría mover isVisible a HomePage, lo que le permitiría pasarlo a ambos componentes. Luego puede actualizar isVisible pasando una función onIsVisibleChange() .

 const HomePage = () => { const [isVisible , setIsVisible] = useState() return ( <> <Livechat onIsVisibleChange={setIsVisible}/> <NewsLetter isVisible={isVisible}/> </> }

Puedes actualizarlo en NewsLetter:

 const NewsLetter = (props) => { const {onIsVisibleChange} = props; const newsLetterRef = useRef(); useEffect( () => { const observer = new IntersectionObserver( (entries) => { const entry = entries[0]; onIsVisibleChange(entry.isIntersecting); }) observer.observe(newsLetterRef.current) } , []) ... }

De manera similar, en Livechat puedes usar la variable así:

 const Livechat = (props) => { const {isVisible} = props; return ( <> <div className={styles.whatsappFloat}> {isVisible && <div className={styles.chatText}> <p>Chat With Us Now</p> </div> } <a href='https://api.whatsapp.com/send?phone=000000000' > <img src={LivechatImg} alt= "/" /> </a> </div> </> ) }
about 4 years ago · Juan Pablo Isaza Report
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!