N
N
nskaskyo2021-09-27 10:28:29
React
nskaskyo, 2021-09-27 10:28:29

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

1 answer(s)
A
Alexandroppolus, 2021-09-27
@Alexandroppolus

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 question

Ask a Question

731 491 924 answers to any question