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

217
Views
Cómo usar onChange en reaccionar-seleccionar

Estoy tratando de crear la función onChange en mi reacción-seleccionar. Aquí está mi siguiente código:

 const find = (event) => { event.preventDefault(); if (event.target.value === "Users") { setSearchUsers(true); setSearchTeams(false); } else if (event.target.value === "Teams") { setSearchUsers(false); setSearchTeams(true); } }; <Select className="search-select" instanceId="long-value-select" closeMenuOnSelect={false} components={animatedComponents} defaultValue="Select" isMulti onChange={(e) => find(e.target.value)} options={searchData} />

Cuando trato de cambiar las opciones me da este error

TypeError: event.preventDefault no es una función

¿Cómo puedo usar la función onChange en este caso?

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

0

Está pasando event.target.value al método de find y luego usa ese valor de evento para obtener event.target.value nuevamente. No necesita volver a hacer esto ya que ya pasó el valor. El método prevenDefault() no existe en el valor del evento, pero existe en el objeto del evento en sí. Simplemente pase el objeto de evento como argumento para usar preventDefault() .

 onChange={(e) => find(e)}
about 4 years ago · Juan Pablo Isaza Report

0

Simplemente actualice onChange así:

 onChange={(e) => find(e)}

o más corto:

 onChange={find}
about 4 years ago · Juan Pablo Isaza Report

0

Este controlador solo pasa el valor del evento para find , no el evento , y el valor no tiene un método preventDefault .

 onChange={(e) => find(e.target.value)}

Pase el evento a la función simplemente usando el controlador...

 onChange={find}

... y luego hacer que la función extraiga el valor

 function find(event) { event.preventDefault(); const { value } = e.target; if (value === 'Users') { // ... } }
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!