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

158
Views
por qué usamos this.initialState = this.state;

¿Alguien puede explicarme por qué usar this.initialState sabiendo que estoy usando el componente de clase aquí en React JS?

 class Inscription extends Component { constructor(props) { super(props); this.state = { pseudo: '', email: '', password: '', formErrors: {} }; this.initialState = this.state; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Imagine tener un formulario con múltiples entradas y, finalmente, el usuario envía todos los datos. Después de un envío exitoso, desea restablecer todo en el formulario. La forma más fácil es hacer this.state = this.initialState para que no necesite definir initialState dos veces.

En lugar de agregar initialState a Class, lo definiría fuera de la clase.

 const initialState = { pseudo: '', email: '', password: '', formErrors: {} }; class Inscription extends Component { constructor(props) { super(props); this.state = initialState; } onSubmit(){ // do backend call // some others events // eventually reset the state this.state = initialState; } }
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!