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

136
Views
How to use event.preventDefault() when function have arguments

i have a code like this:

const upListCandy = (candy) => {
      /* How i add event.preventDefault() and it word*/
      axios.post("example.com", {
         candyName: candy.name
       }).then().catch()
    }

here is my button:

dataCandy?.map((item, index) => {
   return(
      <div key={index}>
        <button onClick = {() => upListCandy(item)}>{item.name}</button>
      </div>
    )   
 })

And my question is how add parameter of event then event.preventDefault() work?

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

0

modify your onclick like so

<button onClick = {(e) => upListCandy(item,e)}>{item.name}</button>

and then

const upListCandy = (candy,event) => {
      event.preventDefault();
      axios.post("example.com", {
         candyName: candy.name
       }).then().catch()
    }
about 4 years ago · Juan Pablo Isaza Report

0

I think you can change it like this

dataCandy?.map((item, index) => {
   return(
      <div key={index}>
        <button onClick = {(e) => upListCandy(e,item)}>{item.name}</button>
      </div>
    )   
 })
const upListCandy = (e,ceandy) => {
      e.preventDefault()
      axios.post("example.com", {
         candyName: candy.name
       }).then().catch()
    }
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!