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

231
Views
Agregar propiedades en this vs agregar propiedades en this.state. ¿Cual es la diferencia?

Sé que los componentes funcionales son más fáciles de usar que los componentes de clase, pero estoy tratando de aprender a hacer cosas usando ambos para comprender mejor. Así que busqué algunos ejemplos en el sitio web oficial de reacción.

El ejemplo del temporizador en reactjs.org/#a-stateful-component agrega seconds como un estado del componente, pero agrega un interval directamente como propiedad de this .

Me pregunto si hay diferencia entre ambos enfoques. ¿Cuándo debo agregar una propiedad en this en lugar de agregarlo como un estado?

 class Timer extends React.Component { constructor(props) { super(props); this.state = { seconds: 0 }; //adding as state } tick() { this.setState(state => ({ seconds: state.seconds + 1 })); } componentDidMount() { this.interval = setInterval(() => this.tick(), 1000); //added property on this } componentWillUnmount() { clearInterval(this.interval); } render() { return ( <div> Seconds: {this.state.seconds} </div> ); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La regla general es. Si desea que algo cambie en UI. Lo actualiza en el estado si no se requiere un cambio de interfaz de usuario. Solo actualizas la propiedad

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!