A
A
Andrey Novikov2020-10-27 13:13:31
React
Andrey Novikov, 2020-10-27 13:13:31

How to pass a string with a component from the server to a React site?

It became interesting whether it is possible to write a full-fledged react component, then convert it to a string. Then send this string to the server. From this server, a certain site would take this string, parse it back into a class with all methods, and display it on the page. If possible, in which direction to google?

As far as I understand, the interactive jsx editor on the react site works in a similar way.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twolegs, 2020-10-27
@Andreeyyy

Read about Server Side Rendering.
https://reactjs.org/docs/react-dom.html#hydrate - this function will help you. But there is a peculiarity - hydrate does not work at the component level, only at the application level. Therefore, individual components will need to be rendered in portals ( https://reactjs.org/docs/portals.html )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question