-1

I'm building an app with React and Flask. React is installed via "create react-app" (yarn). As I don't want to overload the server, I wonder if it is "better" to write math calculus on the React code or on the python server.

This is a basic example: I want to calculate a percentage. I'm getting data from an external API, then send it to React and do the math with a function in javascript on a React components. What exactly do happens? is the function executed on the client? is it executed with typescipt on the node server?

On a final note, would it be lighter to execute that function with the python server or not? (i'm not going into what language is better, it could be any kind of serverside language, i'm trying to determine what exactly is happening on the server and on the client)

Psaume
  • 1
  • 1
  • 2

1 Answers1

0

Its executed on the client, unless you have some setup that has server side rendering -- where it could be executed on both sides. If you're just using create-react-app, then its definitely executing on the client.

On a final note, would it be lighter to execute that function with the python server or not?

If its as simple a calculation as im thinking, calculating a percentage is an incredibly minor thing and its nowhere near significant enough to offload to the server. You are right to think about this -- sometimes it is worth it. If this calculation is intense then it should be considered, but if its just basic multiplication/division its very trivial computation. In that case its totally fine to do this in the react view layer -- which is running inside the users browser.

adsy
  • 8,531
  • 2
  • 20
  • 31
  • thanks for your reply. I was kinda worried about the ES6 transpiling stuff cause i'm not sure how it works yet. – Psaume Sep 04 '22 at 16:19
  • No worries, would you mind marking this as accpeted @Psaume :) ? The transpilation happens on the react-react-app node server -- but this is ultimately a static build time thing that runs inside that server; it doesnt actually execute the code. Alls that node server really is is a thing which serves the static files and does on the fly transpilation (plus hot reloading). Its more of a dev utility. Typically, you would use this only for development and in production you would instead serve the bundled files from your python server. https://create-react-app.dev/docs/production-build/ – adsy Sep 05 '22 at 21:16