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

130
Vistas
Moving functions to other file

Got a file A with almost 2000 lines. Yes, a lot.

So firstly I would need to divide the entire file into smaller sections, so I will need to move a lot of functions to file B from file A and call them in file A to be executed.

Problem is that most of those functions use setState(), gets additional variables from local storage or/and are passed on etc. And there are 41 of them

Example function that needs to be moved to file B from file A

onSubmittedForUserIDChange = (e) => {
    const { value } = e.target;
    const { submitForOtherUser } = this.state;
    if (!submitForOtherUser) {
      this.setState({
        submittedForUserID: +value,
        submitForOtherUser: !submitForOtherUser,
        category_id: null,
        event_type_id: null,
        warning: null,
      });
    } else {
      this.setState({
        submitForOtherUser: !submitForOtherUser,
        submittedForUserID: +localStorage.getItem("user_id"),
      });
    }
  };

It is called in file A jsx component

             <select
              className="form-control"
              name="submittedForUserID"
              onChange={this.onSubmittedForUserIDChange}
              value={
                submittedForUserID === +localStorage.getItem("user_id")
                  ? "-1"
                  : submittedForUserID
              }
              disabled={disabled}
              required
            >

Tried several VSCode extensions that were "supposed" to help with this but really didn't, such as Glean, Abracadabra refractor this!, JS CodeFormer.

Would appreciate tips on how to do it faster than manually

Edit note: Redux is not used in project

about 4 years ago · Juan Pablo Isaza
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