You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -217,7 +217,7 @@ On production deployments that use asset precompilation, such as Heroku deployme
217
217
If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
218
218
219
219
### Rails Context
220
-
When you use a "generator function" to create react components or you used shared redux stores, you get 2 params passed to your function:
220
+
When you use a "generator function" to create react components (or renderedHtml on the server) or you used shared redux stores, you get 2 params passed to your function:
221
221
222
222
1. Props that you pass in the view helper of either `react_component` or `redux_store`
223
223
2. Rails contextual information, such as the current pathname. You can customize this in your config file.
@@ -318,6 +318,8 @@ If you do want different code to run, you'd setup a separate webpack compilation
318
318
#### Generator Functions
319
319
Why would you create a function that returns a React component? For example, you may want the ability to use the passed-in props to initialize a redux store or setup react-router. Or you may want to return different components depending on what's in the props. ReactOnRails will automatically detect a registered generator function.
320
320
321
+
Another reason to user a generator function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }.
322
+
321
323
#### Renderer Functions
322
324
A renderer function is a generator function that accepts three arguments: `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for calling `ReactDOM.render` to manually render a React component into the dom. Why would you want to call `ReactDOM.render` yourself? One possible use case is [code splitting](docs/additional-reading/code-splitting.md).
+**component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component, or a renderer function that manually renders a React component to the dom (client side only).
345
+
+**component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component (or only on the server side, an object with shape { redirectLocation, error, renderedHtml }), or a renderer function that manually renders a React component to the dom (client side only).
344
346
+**options:**
345
347
+**props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
346
348
+**prerender:** enable server-side rendering of component. Set to false when debugging!
0 commit comments