-
-
Notifications
You must be signed in to change notification settings - Fork 631
/
react_on_rails.rb
39 lines (34 loc) · 1.34 KB
/
react_on_rails.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
# For documentation of parameters see: docs/basics/configuration.md
module RenderingExtension
# Return a Hash that contains custom values from the view context that will get passed to
# all calls to react_component and redux_store for rendering
def self.custom_context(view_context)
if view_context.controller.is_a?(ActionMailer::Base)
{}
else
{
somethingUseful: view_context.session[:something_useful]
}
end
end
end
module RenderingPropsExtension
# Return a Hash that contains custom props for all client rendered react_components
def self.adjust_props_for_client_side_hydration(component_name, props)
props[:modificationTarget] = "client-only" if component_name == "HelloWorldProps"
props
end
end
ReactOnRails.configure do |config|
config.server_bundle_js_file = "server-bundle.js"
config.random_dom_id = false # default is true
# Uncomment to test these
# config.build_test_command = "yarn run build:test"
# config.build_production_command = "RAILS_ENV=production NODE_ENV=production bin/shakapacker"
# config.webpack_generated_files = %w[server-bundle.js manifest.json]
config.rendering_extension = RenderingExtension
config.rendering_props_extension = RenderingPropsExtension
config.components_subdirectory = "startup"
config.auto_load_bundle = true
end