I have started learning React Server Side Rendering. Then I configured "index.js" file as follows:
const express = require('express');
const app = express();
const React = require('react');
const renderToString = require('react-dom/server').renderToString;
const Home = require('./client/components/home').default;
app.get('/', (req, res) => {
const content = renderToString(<Home></Home>);
res.send(content); // Statement1
});
app.listen(3000, ()=> {
console.log("App listening to port 3000");
});
So, at Statement1 in above code, we are returning string form "Home" component (because "renderToString" converts HTML into string.
When I inspect DOM, I get following code:
<html>
<head></head>
<body cz-shortcut-listen="true">
<div data-reactroot="">I'm home component</div>
</body>
</html>
So, my question is that how browser is converting HTML string (received as response from server) into DOM elements, and how this "<body>
" tag is being added?