Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

render components ready to be mounted on the browser #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ option | values | default
`jsx.extension` | any file extension with leading `.` | `".jsx"`
`doctype` | any string that can be used as [a doctype](http://en.wikipedia.org/wiki/Document_type_declaration), this will be prepended to your document | `"<!DOCTYPE html>"`
`beautify` | `true`: beautify markup before outputting (note, this can affect rendering due to additional whitespace) | `false`
`static` | `true`: component won't be ready to mount if using `react` on the browser (note, this generates less markup) | `true`

The defaults are sane, but just in case you want to change something, here's how it would look:

Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var DEFAULT_OPTIONS = {
harmony: false
},
doctype: '<!DOCTYPE html>',
beautify: false
beautify: false,
static: true
};

function createEngine(engineOptions) {
Expand All @@ -36,7 +37,14 @@ function createEngine(engineOptions) {
var component = require(filename);
// Transpiled ES6 may export components as { default: Component }
component = component.default || component;
markup += React.renderComponentToStaticMarkup(component(options));

var instance = component(options);

if (engineOptions.static) {
markup += React.renderComponentToStaticMarkup(instance);
} else {
markup += React.renderComponentToString(instance);
}
} catch (e) {
return cb(e);
}
Expand Down