You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get a quick React demo working. I am showing an example below of how when I use a Ruby proc, nothing gets rendered (no errors), but if I return a native JS function rendering the same way, it works fine.
It could be something I have done wrong, or a problem with React, and not Ruby.wasm, but I was curious -- are the two calls I am making below (1 and 2) equivalent? In my understanding they are.
React = JS.global[:React]
class Hash
def to_js
o = JS.global[:Object].create JS::Null
each do |k, v|
o[k.to_sym] = v
end
o
end
end
# 1. This does not work
# root.render React.createElement('div', { hi: 'there' }, (React.createElement proc { |_, _|
# React.createElement 'p', JS::Null, 'hello'
# }))
# 2. This works, but should be the same as 1?
root.render React.createElement 'div', { hi: 'there' },
React.createElement(JS.eval('return function() { return React.createElement("p", null, "hello") }'))
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to get a quick React demo working. I am showing an example below of how when I use a Ruby
proc
, nothing gets rendered (no errors), but if I return a native JS function rendering the same way, it works fine.It could be something I have done wrong, or a problem with React, and not Ruby.wasm, but I was curious -- are the two calls I am making below (1 and 2) equivalent? In my understanding they are.
Beta Was this translation helpful? Give feedback.
All reactions