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

206
Visualizações
Conceptually Question: Passing a function in an object from Backend to Frontend

Consider the following scenario: A front-end application containing

  • Create View (POST) with multiple input fields
  • Edit View (GET values from back-end, PUT if values changed)
  • Both views use the same route.

While a user is in the process of typing values into the inputs, there are several "helper fields" which do (live/instant) calculations based on the inputs of the user. The user is able to see the results of those calculations.

Easy enough a calculations.js located in the front-end, receives the current input values (state) and does the calculations.

Now please consider the following: Results of calculations.js are not saved to the database, since they can be calculated. However, the back-end has to do very similar calculations. Lets say it has to sum up the results of calculations.js in multiple routes. This speaks for putting calculations.js in the back-end. Another possibility: The Edit View shall receive the initial (calculated) values from the back-end.

The dilemma:

  • Putting calculations.js only in the backend, makes it, so that the front-end has to call the back-end all the time while the user is filling in inputs (not practical).
  • Putting calculations.js in both, may lead to data inconsistency and speaks against DRY Principle

In this context i was asking myself if it is possible and/or bad practice to define the function the back-end and pass it in an object to the front-end? Something like

{ calcFunction: (props) => console.log(props) }

How would someone tackle this problem in general? Thank you

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