Skip to content

Commit 339664f

Browse files
committed
Merge branch 'issue-111' into edge
2 parents 5948569 + dce5920 commit 339664f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ruby/hyper-component/lib/hyperstack/internal/component/react_wrapper.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ module Component
1818
class ReactWrapper
1919
@@component_classes = {}
2020

21+
def self.stateless?(ncc)
22+
`typeof #{ncc} === 'function' && !(#{ncc}.prototype && #{ncc}.prototype.isReactComponent)`
23+
end
24+
2125
def self.import_native_component(opal_class, native_class)
2226
opal_class.instance_variable_set("@native_import", true)
2327
@@component_classes[opal_class] = native_class
@@ -29,9 +33,8 @@ def self.eval_native_react_component(name)
2933
is_component_class = `#{component}.prototype !== undefined` &&
3034
(`!!#{component}.prototype.isReactComponent` ||
3135
`!!#{component}.prototype.render`)
32-
is_functional_component = `typeof #{component} === "function"`
3336
has_render_method = `typeof #{component}.render === "function"`
34-
unless is_component_class || is_functional_component || has_render_method
37+
unless is_component_class || stateless?(component) || has_render_method
3538
raise 'does not appear to be a native react component'
3639
end
3740
component
@@ -179,7 +182,7 @@ def self.create_element(type, *args, &block)
179182

180183
# Convert Passed in properties
181184
ele = nil # create nil var for the ref to use
182-
ref = ->(ref) { ele._update_ref(ref) } unless `typeof ncc === 'function'`
185+
ref = ->(ref) { ele._update_ref(ref) } unless stateless?(ncc)
183186
properties = convert_props(type, { ref: ref }, *args)
184187
params << properties.shallow_to_n
185188

@@ -192,7 +195,10 @@ def self.create_element(type, *args, &block)
192195
}
193196
}
194197
end
195-
ele = Hyperstack::Component::Element.new(`React.createElement.apply(null, #{params})`, type, properties, block)
198+
# assign to ele so that the ref callback can use it
199+
ele = Hyperstack::Component::Element.new(
200+
`React.createElement.apply(null, #{params})`, type, properties, block
201+
)
196202
end
197203

198204
def self.clear_component_class_cache

0 commit comments

Comments
 (0)