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: docs/getting-started.md
+18
Original file line number
Diff line number
Diff line change
@@ -121,6 +121,24 @@ issue.
121
121
};
122
122
```
123
123
124
+
- You can pass a block to `react_component`, and it will be provided as the `children` prop to the React component, as a React element:
125
+
```ruby
126
+
<%= react_component("YourComponent") do%>
127
+
<p>ContainedHTML<p>
128
+
<%= render "your/partial"%>
129
+
<% end %>
130
+
```
131
+
```js
132
+
importReactfrom'react';
133
+
134
+
exportdefault (props) => {
135
+
return () => (
136
+
<div>{ props.children }</div>
137
+
);
138
+
};
139
+
```
140
+
**Note that this is implementing using React's [dangerouslySetInnerHtml](https://react.dev/reference/react-dom/components/common#dangerously-setting-the-inner-html)**, so named because of the exposure to cross-site scripting attacks. You should generally be fine since the HTML is coming from your own code via the Rails rendering engine, but this is sharp knife so please exercise caution :)
141
+
124
142
See the [View Helpers API](https://www.shakacode.com/react-on-rails/docs/api/view-helpers-api/) for more details on `react_component` and its sibling function `react_component_hash`.
0 commit comments