Skip to content

Commit adec41d

Browse files
author
Gabe Scholz
committed
Allow #render_react_component to pass in layout and status options
1 parent 7e7413d commit adec41d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/react/rails/controller_helper.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ module ControllerHelper
55
# Render a React component as the view instead of
66
# a template from the app/views folder.
77
#
8-
def render_react_component(*args, &block)
9-
current_layout = _layout.virtual_path
10-
@__react_component_args = args
8+
def render_react_component(name, args = {}, options = {}, &block)
9+
__react_render_component_args = {
10+
inline: '<%= react_component(*@__react_component_args, &@__react_component_block) %>',
11+
layout: options.delete(:layout) || _layout.virtual_path
12+
}
13+
14+
if status = options.delete(:status)
15+
__react_render_component_args.merge!(status: status)
16+
end
17+
18+
@__react_component_args = [name, args, options]
1119
@__react_component_block = block
1220

13-
render inline: '<%= react_component(*@__react_component_args, &@__react_component_block) %>', layout: current_layout
21+
render __react_render_component_args
1422
end
1523

1624
end

0 commit comments

Comments
 (0)