Answer the question
In order to leave comments, you need to log in
How to pass a function from server to client with SSR?
Good day.
There is a task to make an SSR (React, Nodejs, without Next and express)
SPA of a regular calculator, but so that the server gives the page with the calculator and all calculations are made on the server.
What we managed to figure out: that instead of render you need hydrate and on the server renderToString. It was possible to transfer the result of calculations from the server.
Problem: How to pass functions from the server to the client to use them when clicking on the buttons?
(make endpoints and fetch, or you can still somehow pass the functions as props for the component to which the renderToString will be applied. Well, or in general. everything is wrong)
Thanks in advance
Answer the question
In order to leave comments, you need to log in
A strange wish. This is an SEO requirement - should the calculator be indexed by search engines? Or do you need a lot of data for calculations, and is it easier to calculate on the server than to transfer them to the client? In all other cases, it is more convenient to count at the front.
And what does it mean to pass functions? Any formulas? Are they dynamically generated?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question