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

154
Views
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 answers
Answer question

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 Report

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 Report

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 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!