Skip to content

Commit 4ee47c3

Browse files
committed
Make props_to_json a pure function with options
1 parent 4e7a1c6 commit 4ee47c3

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/react/rails/component_mount.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ def generate_html_options(name, options, props, prerender_options)
5656
unless prerender_options == :static
5757
html_options[:data].tap do |data|
5858
data[:react_class] = name
59-
data[:react_props] = props_to_json(props)
59+
data[:react_props] = props_to_json(
60+
props,
61+
null_to_undefined: Dummy::Application.config.react.null_to_undefined_props
62+
)
6063
data[:hydrate] = "t" if prerender_options
6164

6265
num_components = @cache_ids.count { |c| c.start_with? name }
@@ -67,9 +70,9 @@ def generate_html_options(name, options, props, prerender_options)
6770
html_options
6871
end
6972

70-
def props_to_json(props)
73+
def props_to_json(props, options = { null_to_undefined: false })
7174
return props if props.is_a?(String)
72-
return props.to_json unless Dummy::Application.config.react.null_to_undefined_props
75+
return props.to_json unless options[:null_to_undefined]
7376

7477
# This regex matches key:value with null values while ensuing no string with similar
7578
# pattern gets matched. It doesn't include null values in arrays.

0 commit comments

Comments
 (0)