Skip to content

Commit e712d9a

Browse files
author
Gabe Scholz
committed
Add documentation for component rendering
1 parent 4aba49a commit e712d9a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ end
203203
- On MRI, you'll get a deadlock with `pool_size` > 1
204204
- If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering.
205205

206+
### Rendering components instead of views
207+
208+
Components can also be prerendered directly from a controller action with the custom `component` renderer. For example:
209+
210+
```ruby
211+
class TodoController < ApplicationController
212+
def index
213+
@todos = Todo.all
214+
render component: 'TodoList', props: { todos: @todos }, tag: 'span'
215+
end
216+
end
217+
```
218+
219+
This custom renderer behaves the same as a normal view renderer and accepts the usual arguments - `content_type`, `layout`, `location` and `status`.
220+
By default, your current layout will be used and the component will be rendered in place of `yield` rather than a view.
221+
206222
### Component generator
207223

208224
`react-rails` ships with a Rails generator to help you get started with a simple component scaffold.

0 commit comments

Comments
 (0)