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

194
Views
Cómo configurar la visibilidad en reaccionar mecanografiado en la carga de la página

Estoy creando un consentimiento de cookies en una aplicación de reacción donde los usuarios pueden aceptar o rechazar. Si el usuario ya ha aceptado el concepto de cookie, no volver a mostrar.

Quiero verificar en la carga de la página si el elemento ya está configurado, no mostrar el consentimiento, sino mostrar (html a oculto). Pero el problema es que en el evento onLoad, el documento no está listo. ¿Cómo puedo arreglar esto?

Además, descubrí que en la carga de la página se presiona "OnpageLoad ()"

Aceptar y rechazar funcionando bien

cookieconsent.ts

 const storageType = localStorage; const consentPropertyName = "jdc_consent"; const saveToStorage = () => storageType.setItem(consentPropertyName, "true"); class UserConsent { OnpageLoad() { debugger; const shouldShowPopUp = storageType.getItem(consentPropertyName); if (shouldShowPopUp != "true") { let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); } } async acceptConsent() { debugger; saveToStorage(); let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); //html.style.display === "block"; } async rejectConcent() { storageType.removeItem(consentPropertyName); let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); } } export default new UserConsent();

ver.tsx

 <div> <div> ... </div> <div id="consent-pop" onLoad={cookieconsent.OnpageLoad} style={{ position: "fixed", bottom: 0, left: 0, right: "0", }} className="visible" > <p> By using this site you agree to our Terms and Conditions{" "} <a onClick={cookieconsent.acceptConsent}>Accept</a> or{" "} <a onClick={cookieconsent.rejectConcent}>Reject</a> </p> </div> </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Prueba esto:

 const storageType = localStorage; const consentPropertyName = "jdc_consent"; const saveToStorage = () => storageType.setItem(consentPropertyName, "true"); class UserConsent { componentDidMount() { window.addEventListener('load', this.handleLoad); } handleLoad() { debugger; const shouldShowPopUp = storageType.getItem(consentPropertyName); if (shouldShowPopUp != "true") { let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); } } async acceptConsent() { debugger; saveToStorage(); let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); //html.style.display === "block"; } async rejectConcent() { storageType.removeItem(consentPropertyName); let html = document.getElementById("consent-pop") as HTMLElement; html.classList.add("hidden"); } } export default new UserConsent();

Tal vez como una alternativa, intente con useEffect también.

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!