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

263
Views
Cómo: onClick/onChange para una <opción> de <select> en un componente secundario

¿Hay alguna manera de tener un componente secundario que represente solo una etiqueta <option> para activar onChange de su <select> principal?

Pregunto porque probé onClick y onChange en el niño <option> y parece estar distante de ellos.

La idea es un componente principal de React que se ve así:

 render() { return ( <select value={this.state.value} onChange={this.handleChange}> <ChildOption onClick={this.handleChange} </select> ); }

y el componente ChildOption así:

 render() { return ( <option onClick={this.handleClick} /> ); }

El código completo para este problema está aquí en un CodePen (suponga que está devolviendo una matriz de <option> s:

  • http://codepen.io/mikeumus/pen/BpzeYO?editors=0010

Código del mundo real aquí en Cloud9:

  • https://ide.c9.io/mikeumus/ca-blinds#imports/plugins/included/product-detail-simple/client/components/variantList.js:205
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede tener un componente secundario que solo represente la etiqueta de option . En realidad, no necesita agregar un controlador de eventos a la etiqueta de option . El evento select onChange se llama automáticamente una vez que se hace clic en una etiqueta de option (pasando su valor con ella).

Vea el ejemplo aquí: http://codepen.io/anon/pen/oBzzWr?editors=0010

over 4 years ago · Santiago Trujillo 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!