Skip to content

Commit 2b75bc1

Browse files
author
Madeline Trotter
authored
Merge pull request #6 from deviant-forks/react-dom-server
Add `renderToString` and `renderToStaticMarkup`
2 parents c5587d2 + 9613dd7 commit 2b75bc1

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/React/Basic/DOM/Server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
3+
const ReactDOMServer = require("react-dom/server");
4+
5+
exports.renderToString = ReactDOMServer.renderToString;
6+
7+
exports.renderToStaticMarkup = ReactDOMServer.renderToStaticMarkup;

src/React/Basic/DOM/Server.purs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module React.Basic.DOM.Server
2+
( renderToString
3+
, renderToStaticMarkup
4+
) where
5+
6+
import React.Basic (JSX)
7+
8+
-- | Render a React element to its initial HTML. React will return an HTML string.
9+
-- | You can use this method to generate HTML on the server and send the markup
10+
-- | down on the initial request for faster page loads and to allow search engines
11+
-- | to crawl your pages for SEO purposes.
12+
-- |
13+
-- | If you call `ReactDOM.hydrate` on a node that already has this server-rendered
14+
-- | markup, React will preserve it and only attach event handlers, allowing you to
15+
-- | have a very performant first-load experience.
16+
foreign import renderToString :: JSX -> String
17+
18+
-- | Similar to `renderToString`, except this doesn’t create extra DOM attributes
19+
-- | that React uses internally, such as `data-reactroot`. This is useful if you
20+
-- | want to use React as a simple static page generator, as stripping away the
21+
-- | extra attributes can save some bytes.
22+
-- |
23+
-- | If you plan to use React on the client to make the markup interactive, do not
24+
-- | use this method. Instead, use `renderToString` on the server and `ReactDOM.hydrate`
25+
-- | on the client.
26+
foreign import renderToStaticMarkup :: JSX -> String

0 commit comments

Comments
 (0)