-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var React = require('react');
var ReactDOM = require('react-dom');
var ServersideWrapper = React.createClass({
propTypes: {
element: React.PropTypes.string.isRequired,
properties: React.PropTypes.object.isRequired
},
render: function() {
var json = JSON.stringify(this.props.properties);
return React.createElement('script', { type: 'application/json',
id: this.props.element + '_props',
dangerouslySetInnerHTML: { __html: json.replace(/\//g, '\\/') }
});
}
});
// This method is used to create the initial dom node that react attaches itself to
ServersideWrapper.createDomElement = function(opts) {
if (typeof window !== 'undefined' && document.getElementById(opts.domElement + '_props') !== null) {
var componentProperties = JSON.parse(
document.getElementById(opts.domElement + '_props').innerHTML
);
ReactDOM.render(React.createElement(opts.component, componentProperties),
document.getElementById(opts.domElement));
}
};
module.exports = ServersideWrapper;