Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda