Skip to content

Commit 4f8b542

Browse files
committed
Add isomorphic/universal README example, and a CodePen demo
1 parent 47f3266 commit 4f8b542

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Render JSX and [Preact] components to an HTML string.
77

88
Works in Node & the browser, making it useful for universal/isomorphic rendering.
99

10+
\>\> **[Cute Fox-Related Demo](http://codepen.io/developit/pen/dYZqjE?editors=001)** _(@ CodePen)_ <<
11+
1012

1113
---
1214

@@ -59,6 +61,37 @@ console.log(html);
5961
---
6062

6163

64+
### Render JSX / Preact / Whatever via Express!
65+
66+
```js
67+
import express from 'express';
68+
import { h } from 'preact';
69+
import render from 'preact-render-to-string';
70+
71+
// silly example component:
72+
const Fox = ({ name }) => (
73+
<div class="fox">
74+
<h5>{ name }</h5>
75+
<p>This page is all about {name}.</p>
76+
</div>
77+
);
78+
79+
// basic HTTP server via express:
80+
const app = express();
81+
app.listen(8080);
82+
83+
// on each request, render and return a component:
84+
app.get('/:fox', (req, res) => {
85+
let html = render(<Fox name={req.params.fox} />);
86+
// send it back wrapped up as an HTML5 document:
87+
res.send(`<!DOCTYPE html><html><body>${html}</body></html>`);
88+
});
89+
```
90+
91+
92+
---
93+
94+
6295
### License
6396

6497
[MIT]

0 commit comments

Comments
 (0)