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

278
Views
React Boostrap Select, First Select Option no se activa con el evento onChange

Estoy usando el componente React Boostrap Select:

 <Form.Group className="mb-1"> <Form.Label htmlFor="type" className="iig-form-label d-inline-block text-truncate" > Type de projet &nbsp; {loadingTypes && <Spinner animation="grow" size="sm" />} </Form.Label> <Form.Select required aria-label="Default select example" id="type" name="type" onChange={(e) => handleChange(e)} isInvalid={false} > // THIS IS THE DEFAULT OPTION THAT IS NOT TRIGGERED <------------------- <option value={currentType ? currentType["@id"] : ""} data-category={ currentType ? currentType?.category?.label : "" } > {currentType ? currentType.label : `Choisir parmi la liste des types de projets`} </option> {filteredTypes.map((filteredTypes, key) => { return ( <option value={`/api/types/${filteredTypes.id}`} data-category={filteredTypes.category.label} key={key} > {filteredTypes.label} </option> ); })}

Agregué una opción predeterminada para mostrar.

Cuando hago clic en la opción predeterminada, el evento onChange no se activa.

¿Cómo puedo arreglar eso?

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

0

No pude seguir tu ejemplo, así que creé un ejemplo mínimo para mostrarte cómo funciona:

  • Cree un estado para almacenar el valor y proporcione la identificación/valor de la opción seleccionada que desea ver inicialmente como valor predeterminado
  • Escribir en el controlador de cambios
  • Pase el valor del estado y el controlador onChange a Form.Select
  • En Form.Select iterar sobre su lista de opciones seleccionadas

.

 const selectOptions = [ { value: "js", label: "Javascript" }, { value: "ja", label: "Java" }, { value: "py", label: "Python" }, { value: "go", label: "Go" }, { value: "cs", label: "C#" } ]; export default function App() { const [value, selectValue] = useState("js"); const handleChange = (event) => selectValue(event.target.value); return ( <Form.Group className="mb-1"> <Form.Select value={value} onChange={handleChange}> {selectOptions.map((option) => { return <option value={option.value}>{option.label}</option>; })} </Form.Select> </Form.Group> ); }

https://codesandbox.io/s/dreamy-gwen-yfmw1m

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!