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

127
Views
No se pueden insertar valores de estado en un objeto

Tengo este estado en mi clase:

 this.state = { inputValue: "", todos: [] }

En una función de flecha, estoy tratando de establecer inputValue setState todos .

 this.setState({ inputValue: "", todos: [...this.state.todos, {this.state.todos.length: this.state.inputValue}] })

Sin embargo, cuando intento insertar el valor de inputValue y el número, da un error. Se agradece cualquier ayuda ya que soy nuevo en React.

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

0

Si desea una matriz resultante de todos como esta:

 [ {0: "something"}, {1: "Else"} ]

La notación de corchetes es necesaria para usar una variable como clave de objeto.

 this.setState({ inputValue: "", todos: [ ...this.state.todos, { [this.state.todos.length]: this.state.inputValue } ] });
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!