Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda