Skip to content
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
11 changes: 9 additions & 2 deletions react_ujs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var detectEvents = require("./src/events/detect")
var constructorFromGlobal = require("./src/getConstructor/fromGlobal")
var constructorFromRequireContextWithGlobalFallback = require("./src/getConstructor/fromRequireContextWithGlobalFallback")

var renderWithReactDOM = require("./src/renderComponent/withReactDOM")

var ReactRailsUJS = {
// This attribute holds the name of component which should be mounted
// example: `data-react-class="MyApp.Items.EditForm"`
Expand Down Expand Up @@ -80,6 +82,11 @@ var ReactRailsUJS = {
return ReactDOMServer[renderFunction](element)
},

// Render `component` using the specified `renderFunction` from `react-dom`.
// Override this function to render components in a custom way.
// function signature: ("hydrate" | "render", component, node, props)
renderComponent: renderWithReactDOM,

// Within `searchSelector`, find nodes which should have React components
// inside them, and mount them with their props.
mountComponents: function(searchSelector) {
Expand Down Expand Up @@ -112,9 +119,9 @@ var ReactRailsUJS = {
}

if (hydrate && typeof ReactDOM.hydrate === "function") {
component = ReactDOM.hydrate(component, node);
renderComponent("hydrate", component, node, props);
} else {
component = ReactDOM.render(component, node);
renderComponent("render", component, node, props);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions react_ujs/src/renderComponent/withReactDOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var ReactDOM = require("react-dom")

// Render React component via ReactDOM, for example:
//
// - `renderComponent("hydrate", component, node, props)` -> `ReactDOM.hydrate(component, node);`
// - `renderComponent("render", component, node, props)` -> `ReactDOM.render(component, node);`
//
module.exports = function(renderFunctionName, component, node) {
ReactDOM[renderFunctionName](component, node);
};