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

208
Vistas
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 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