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

187
Vistas
React, set body style conditionally by adding a class related to a state

I have the following, where I am trying to change the body style while the image is uploading (so the user knows it is uploading). How can I attach a class to the body while the image is uploading and then remove it once the image has uploaded?

const [uploadingImage, setUploadingImage] = useState(false)

    const uploadToFirebase = e => {
        e.preventDefault();
        if (image) {
          const storageRef = storage.ref(`${user1}/${tripid}/documents`);
          const imageRef = storageRef.child(image.name);
          
          setUploadingImage(true)
          imageRef.put(image)
            .then((url) => {
              alert("Successfully uploaded.");
              getFromFirebase();
              setUploadingImage(false)
            })
            .catch(e => setUploadingImage(false));
        } else {
          alert("Please upload an image first.");
        }
      };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use an useEffect, something like this:

useEffect(()=>{
  document.body.classList.toggle("image-uploading", uploadingImage);
},[uploadingImage])

Then add this in your css:

body.image-uploading{
  /* whatever style you want goes here*/
}
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