Skip to content

Commit fbb1060

Browse files
add helper function to render a whole view
1 parent 8687a05 commit fbb1060

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/react_on_rails/helper.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,23 @@ def stream_react_component(component_name, options = {})
102102
end
103103

104104
def stream_react_component_async(component_name, options = {})
105-
Fiber.new do
105+
rendering_fiber = Fiber.new do
106106
stream = stream_react_component(component_name, options)
107107
stream.each_chunk do |chunk|
108108
Fiber.yield chunk
109109
end
110110
Fiber.yield nil
111111
end
112+
113+
if @rorp_rendering_fibers.nil?
114+
raise ReactOnRails::Error, "You must call stream_view_containing_react_components to render the view containing the react component"
115+
end
116+
@rorp_rendering_fibers << rendering_fiber
117+
118+
# return the first chunk of the fiber
119+
# It contains the initial html of the component
120+
# all updates will be appended to the stream sent to browser
121+
rendering_fiber.resume
112122
end
113123

114124
# react_component_hash is used to return multiple HTML strings for server rendering, such as for

0 commit comments

Comments
 (0)