Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
Reaccionar js componenteDidUpdate
componentDidUpdate = (prevProps, prevState) => { if ( prevState.sourceOpt !== this.state.sourceOpt || prevState.destOpt !== this.state.destOpt || prevState.tripOpt !== this.state.tripOpt || prevState.fuelOpt !== this.state.fuelOpt || prevState.minKm !== this.state.minKm || prevState.Configure?.grossEarnings !== this.state.Configure?.grossEarnings || prevState.rateOpt !== this.state.rateOpt || prevState.extra_rate_per_km !== this.state.extra_rate_per_km || prevState.waitingCharge !== this.state.waitingCharge || prevState.wait !== this.state.wait || prevState.categoryOpt !== this.state.categoryOpt || prevState.modelOpt !== this.state.modelOpt ) { this.getDestinationCity() this.getTripBasedOnCity() this.getVehicleCategory() this.getFuelType() this.props.parentCallback(this.state.Configure?.grossEarnings) this.getGeneralData() this.getModelBaseOnCategory() this.getConfiguration() this.getAllData() } if (prevState.fuelOpt !== this.state.fuelOpt) { this.getMinKilo() } if (prevState.changeFareKm !== this.state.changeFareKm || prevState.changeFare !== this.state.changeFare ) { this.handleBlur() } }

¿Hay alguna forma de optimizar este código? Quiero optimizar este código. ¿Hay alguna forma en que pueda hacer que este código sea más legible?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Comprobación del método de condición

 public checkCondition(prevState){ return (prevState.sourceOpt !== this.state.sourceOpt || prevState.destOpt !== this.state.destOpt || prevState.tripOpt !== this.state.tripOpt || prevState.fuelOpt !== this.state.fuelOpt || prevState.minKm !== this.state.minKm || prevState.Configure?.grossEarnings !== this.state.Configure?.grossEarnings || prevState.rateOpt !== this.state.rateOpt || prevState.extra_rate_per_km !== this.state.extra_rate_per_km || prevState.waitingCharge !== this.state.waitingCharge || prevState.wait !== this.state.wait || prevState.categoryOpt !== this.state.categoryOpt || prevState.modelOpt !== this.state.modelOpt) }

método de tomar acciones

 public performActions(){ this.getDestinationCity() this.getTripBasedOnCity() this.getVehicleCategory() this.getFuelType() this.props.parentCallback(this.state.Configure?.grossEarnings) this.getGeneralData() this.getModelBaseOnCategory() this.getConfiguration() this.getAllData() }

Ahora su componenteDidUpdate será

 public componentDidUpdate (prevProps, prevState) { if (this.checkCondition(prevState)) { this.performActions(); } if (prevState.fuelOpt !== this.state.fuelOpt) { this.getMinKilo() } if (prevState.changeFareKm !== this.state.changeFareKm || prevState.changeFare !== this.state.changeFare) { this.handleBlur() } }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda