@@ -18,6 +18,16 @@ module Component
1818 class ReactWrapper
1919 @@component_classes = { }
2020
21+ def self . stateless? ( ncc )
22+ %x{
23+ typeof #{ ncc } === 'function' // can be various things
24+ && !(
25+ #{ ncc } .prototype // native arrows don't have prototypes
26+ && #{ ncc } .prototype.isReactComponent // special property
27+ )
28+ }
29+ end
30+
2131 def self . import_native_component ( opal_class , native_class )
2232 opal_class . instance_variable_set ( "@native_import" , true )
2333 @@component_classes [ opal_class ] = native_class
@@ -29,9 +39,8 @@ def self.eval_native_react_component(name)
2939 is_component_class = `#{ component } .prototype !== undefined` &&
3040 ( `!!#{ component } .prototype.isReactComponent` ||
3141 `!!#{ component } .prototype.render` )
32- is_functional_component = `typeof #{ component } === "function"`
3342 has_render_method = `typeof #{ component } .render === "function"`
34- unless is_component_class || is_functional_component || has_render_method
43+ unless is_component_class || stateless? ( component ) || has_render_method
3544 raise 'does not appear to be a native react component'
3645 end
3746 component
@@ -179,7 +188,7 @@ def self.create_element(type, *args, &block)
179188
180189 # Convert Passed in properties
181190 ele = nil # create nil var for the ref to use
182- ref = -> ( ref ) { ele . _update_ref ( ref ) } unless `typeof ncc === 'function'`
191+ ref = -> ( ref ) { ele . _update_ref ( ref ) } unless stateless? ( ncc )
183192 properties = convert_props ( type , { ref : ref } , *args )
184193 params << properties . shallow_to_n
185194
@@ -192,7 +201,9 @@ def self.create_element(type, *args, &block)
192201 }
193202 }
194203 end
195- ele = Hyperstack ::Component ::Element . new ( `React.createElement.apply(null, #{ params } )` , type , properties , block )
204+ Hyperstack ::Component ::Element . new (
205+ `React.createElement.apply(null, #{ params } )` , type , properties , block
206+ )
196207 end
197208
198209 def self . clear_component_class_cache
0 commit comments