• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

93
Views
Retorno de entrada de reactjs indefinido

Entrada que regresa indefinida, también agregué la función onChange a la entrada, this.state.quantity regresa indefinida en la consola

OrdenMed.js:

 export default class OrderMed extends Component { constructor(props){ super(props); this.state = { Meds: [], quantity: '', id:'' } this.onChange = this.onChange.bind(this); } onChange(e) { this.setState({quantity: e.target.quantity}) } render() { return ( ... <form > <input min={1} placeholder='quantity' type='number' value={this.state.quantity} onChange={this.onChange} id="quantity"></input> <button onClick={() => console.log(this.state.quantity)} id='btn-color1' class="btn btn-color ml-2 px-3 mb-2 w-1">&#10003;</button> </form> ... ) }
almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

solo debe establecer event.target.value en la función onChange de esta manera:

 onChange(e) { this.setState({quantity: e.target.value}) }
almost 3 years ago · Juan Pablo Isaza Report

0

debe optar por funciones de flecha en lugar de las antiguas, reduce las complejidades y se perdió el valor del elemento de destino

 export default class OrderMed extends Component { constructor(props){ super(props); this.state = { Meds: [], quantity: '', id:'' } } onChange = (e) => { const quantity = e.target.value; this.setState({quantity}) } render() { return ( ... <form > <input min={1} placeholder='quantity' type='number' value={this.state.quantity} onChange={this.onChange} id="quantity"></input> <button onClick={() => console.log(this.state.quantity)} id='btn-color1' class="btn btn-color ml-2 px-3 mb-2 w-1">&#10003;</button> </form> ... ) }
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error