2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Render React on the Server with renderToString
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Render React on the Server with renderToString
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
You pass a ```class``` to ```.renderToString()``` just like you would pass a component to a ```render``` method.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```jsx
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return <div/>
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// change code below this line
|
|
|
|
ReactDOMServer.renderToString(<App />);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|