tengo un código como este:
const upListCandy = (candy) => { /* How i add event.preventDefault() and it word*/ axios.post("example.com", { candyName: candy.name }).then().catch() }aquí está mi botón:
dataCandy?.map((item, index) => { return( <div key={index}> <button onClick = {() => upListCandy(item)}>{item.name}</button> </div> ) })Y mi pregunta es ¿cómo funciona agregar el parámetro de evento y luego event.preventDefault()?
modifica tu onclick así
<button onClick = {(e) => upListCandy(item,e)}>{item.name}</button>y entonces
const upListCandy = (candy,event) => { event.preventDefault(); axios.post("example.com", { candyName: candy.name }).then().catch() }Creo que puedes cambiarlo así.
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() }