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

193
Views
¿Cómo establecer los siguientes valores de estado en función de los valores anteriores en React?

Aquí hay un ejemplo:

 class MyComp extends React.Component { constructor(props) { super(props); this.state = { firstName: 'xyz', lastName: 'abc'; fullName: firstName + lastName }; }

Probar la técnica anterior me da errores. También intenté usar this.firstName y this.lastName pero eso también resultó en errores. ¿Cómo debo proceder?

Gracias.

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

0

Puedes probar de la siguiente manera

 class MyComp extends React.Component { constructor(props) { super(props); const firstName = 'xyz'; const lastName = 'abc'; this.state = { firstName, lastName, fullName: firstName + lastName }; }

about 4 years ago · Juan Pablo Isaza Report

0

deberías usar this.state.firstname.....

porque usa el estado en el constructor y si desea acceder a ese elemento, debe definir this.state.'your item name'

 class MyComp extends React.Component {

constructor(accesorios) { super(accesorios);

 const firstName = 'xyz'; const lastName = 'abc'; this.state = { firstName, lastName, fullName: firstName + lastName };

}

en esto puedes usar this.state.firstname

about 4 years ago · Juan Pablo Isaza Report

0

Puede configurar después de montar el componente, si su escenario lo permite.

 this.state = { firstName: 'xyz', lastName: 'abc', fullName: null, };

después

 componentDidMount() { this.setState({ fullName : this.firstName + this.lastName }) }
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!