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

155
Vistas
How to add two functions to one onClick

I have two functions that need to be hung on one button. One function writes data to the Firestore, and the other writes a picture to Storage. How can I add them to the onClick on a single button?

const Header = () => {

  const submitHandler = async (e) => {
    e.preventDefault();
    try {
      await setDoc(doc(housesRef, enteredTitle), {
        title: enteredTitle,
        descr: enteredText,
        lat: enteredLatitude,
        lon: enteredLongitude,
      });
      togglePopup();
      setEnteredTitle("");
      setEnteredText("");
      setEnteredLatitude("");
      setEnteredLongitude("");
    } catch (err) {
      alert(err);
    }
  };

   const imageUpload = () => {
   const imageRef = ref(storage, `image/${uploadImage.name}`);
   uploadBytes(imageRef, uploadImage).then(() => {
   alert("Image Uploaded");
     });
   };

  return (
    <div className="header">
     ...
                  <input
                    type="submit"
                    value="Add"
                    onClick={}
                  />
     ...
   
  );
};

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Simply create a new function that calls those two different functions,

like so,

const myEncapsulatingFunc = (func1_params, func2_params) => {
  myFunc1(func1_params);
  myFunc2(func2_params);
}

Attach myEncapsulatingFunc to the onclick event and pass in the relevant parameters.

about 4 years ago · Juan Pablo Isaza Denunciar

0

The simple answer is you can't

You can however, just call them seperately like this:

return (
    <div className="header">
     ...
                  <input
                    type="submit"
                    value="Add"
                    onClick={() => {
                               func1();
                               func2()
                            } }
                  />
     ...
   
  );
about 4 years ago · Juan Pablo Isaza Denunciar

0

Why not calling imageUpload inside onSubmitHandler and just passing onSubmitHandler to the onClick?

const submitHandler = async (e) => {
    e.preventDefault();
    imageUpload()
    try {
...
    } catch (err) {
      alert(err);
    }
  };
    
<input
   type="submit"
   value="Add"
   onClick={onSubmitHandler}
 />
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