From a0d6fcb3d7893dce9ea04dd538150d994a087cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Magalha=CC=83es?= Date: Thu, 30 Oct 2014 20:32:05 +0000 Subject: [PATCH] render components ready to be mounted on the browser --- README.md | 1 + index.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c324a78..35c4b11 100644 --- a/README.md +++ b/README.md @@ -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 | `""` `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: diff --git a/index.js b/index.js index 399f13c..df4125b 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,8 @@ var DEFAULT_OPTIONS = { harmony: false }, doctype: '', - beautify: false + beautify: false, + static: true }; function createEngine(engineOptions) { @@ -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); }