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
* Added configuration option random_dom_id
* Added method RenderOptions has_random_dom_id?
This new global and react_component helper option allows configuring
whether or not React on Rails will automatically add a random id to the
DOM node ID.
Copy file name to clipboardExpand all lines: docs/api/view-helpers-api.md
+15
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@
3
3
4
4
Once the bundled files have been generated in your `app/assets/webpack` folder and you have registered your components, you will want to render these components on your Rails views using the included helper method, `react_component`.
-**id:** Id for the div, will be used to attach the React component. This will get assigned automatically if you do not provide an id. Must be unique.
25
27
-**html_options:** Any other HTML options get placed on the added div for the component. For example, you can set a class (or inline style) on the outer div so that it behaves like a span, with the styling of `display:inline-block`.
26
28
-**trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise. Only on the **client side** will you will see the `railsContext` and your props.
29
+
-**random_dom_id:** True to automatically generate random dom ids when using multiple instances of the same React component on one Rails view.
27
30
-**options if prerender (server rendering) is true:**
28
31
-**replay_console:** Default is true. False will disable echoing server-rendering logs to the browser. While this can make troubleshooting server rendering difficult, so long as you have the configuration of `logging_on_server` set to true, you'll still see the errors on the server.
29
32
-**logging_on_server:** Default is true. True will log JS console messages and errors to the server.
30
33
-**raise_on_prerender_error:** Default is false. True will throw an error on the server side rendering. Your controller will have to handle the error.
### cached_react_component and cached_react_component_hash
72
78
Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on_rails/wiki) feature. The API is the same as the above, but for 2 differences:
73
79
@@ -79,10 +85,13 @@ Fragment caching is a [React on Rails Pro](https://github.com/shakacode/react_on
79
85
some_slow_method_that_returns_props
80
86
end%>
81
87
```
88
+
------------
89
+
82
90
### rails_context
83
91
84
92
You can call `rails_context(server_side: true | false)` from your controller or view to see what values are are in the Rails Context. Pass true or false depending on whether you want to see the server side or the client side rails_context.
85
93
94
+
------------
86
95
87
96
### Renderer Functions (function that will call ReactDOM.render or ReactDOM.hydrate)
88
97
@@ -92,6 +101,8 @@ Why would you want to call `ReactDOM.hydrate` yourself? One possible use case is
92
101
93
102
Renderer functions are not meant to be used on the server since there's no DOM on the server. Instead, use a generator function. Attempting to server render with a renderer function will throw an error.
94
103
104
+
------------
105
+
95
106
### React Router
96
107
97
108
[React Router](https://github.com/reactjs/react-router) is supported, including server-side rendering! See:
@@ -100,6 +111,8 @@ Renderer functions are not meant to be used on the server since there's no DOM o
100
111
2. Examples in [spec/dummy/app/views/react_router](../../spec/dummy/app/views/react_router) and follow to the JavaScript code in the [spec/dummy/client/app/startup/ServerRouterApp.jsx](../../spec/dummy/client/app/startup/ServerRouterApp.jsx).
101
112
3. [Code Splitting docs](../misc-pending/code-splitting.md) for information about how to set up code splitting for server rendered routes.
102
113
114
+
------------
115
+
103
116
## server_render_js
104
117
105
118
`server_render_js(js_expression, options = {})`
@@ -109,6 +122,8 @@ Renderer functions are not meant to be used on the server since there's no DOM o
109
122
110
123
This is a helper method that takes any JavaScript expression and returns the output from evaluating it. If you have more than one line that needs to be executed, wrap it in an IIFE. JS exceptions will be caught and console messages handled properly.
111
124
125
+
------------
126
+
112
127
# More details
113
128
114
129
See the [lib/react_on_rails/helper.rb](../../lib/react_on_rails/helper.rb) source.
0 commit comments