Issue
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)
Solution
It's 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 it's definitely executing on the client.
On a final note, would it be lighter to execute that function with the python server or not?
If it's as simple a calculation as I'm thinking, calculating a percentage is an incredibly minor thing and it's 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 it's just basic multiplication/division it's very trivial computation. In that case it's totally fine to do this in the React view layer -- which is running inside the users browser.
Answered By - adsy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.