Skip to content

Commit bfdb39f

Browse files
committed
Merge pull request #74 from sjltaylor/lazy-load-view-helper
Lazy load the React Rails view helper in a railstie
2 parents a77b43e + bb54842 commit bfdb39f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/react/rails/railtie.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class Railtie < ::Rails::Railtie
1919
app.config.watchable_files.concat Dir["#{app.root}/app/assets/javascripts/**/*.jsx*"]
2020
end
2121

22+
# Include the react-rails view helper lazily
23+
initializer "react_rails.setup_view_helpers" do
24+
ActiveSupport.on_load(:action_view) do
25+
include ::React::Rails::ViewHelper
26+
end
27+
end
28+
2229
# run after all initializers to allow sprockets to pick up react.js and
2330
# jsxtransformer.js from end-user to override ours if needed
2431
initializer "react_rails.setup_vendor", :after => "sprockets.environment", group: :all do |app|

lib/react/rails/view_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,3 @@ def react_component(name, args = {}, options = {}, &block)
2323
end
2424
end
2525
end
26-
27-
ActionView::Base.class_eval do
28-
include ::React::Rails::ViewHelper
29-
end

0 commit comments

Comments
 (0)