-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from fortedigital/9-serialization-of-props-to-…
…json-is-happening-twice Add json props to html as script tag. Hydrate based of props from scr…
- Loading branch information
Showing
3 changed files
with
35 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
module.exports = (callback, componentName, props = {}, scriptFiles) => { | ||
scriptFiles.forEach((scriptFile) => { require(scriptFile) }); | ||
module.exports = ( | ||
callback, | ||
componentName, | ||
jsonContainerId, | ||
props = {}, | ||
scriptFiles | ||
) => { | ||
scriptFiles.forEach((scriptFile) => { | ||
require(scriptFile); | ||
}); | ||
const component = global[componentName]; | ||
|
||
const component = global[componentName]; | ||
const ReactDOMServer = global["ReactDOMServer"]; | ||
const React = global["React"]; | ||
const element = React.createElement(component, props); | ||
|
||
const ReactDOMServer = global["ReactDOMServer"]; | ||
const React = global["React"]; | ||
const element = React.createElement(component, props); | ||
const componentHtml = `${ReactDOMServer.renderToString(element)}`; | ||
const jsonHtml = `<script id="${jsonContainerId}" type="json">${JSON.stringify( | ||
props | ||
)}</script>`; | ||
const result = componentHtml + jsonHtml; | ||
|
||
const result = ReactDOMServer.renderToString(element); | ||
|
||
callback(null /* error */, result /* result */); | ||
} | ||
callback(null /* error */, result /* result */); | ||
}; |