我正在尝试使用以下代码:
class HelloWorld < React::Component::Base
# stuff
def render
div { "hello" }
div { "goodby" }
end
end
但我一直收到这个错误:
Exception raised while rendering #<HelloWorld:0x489>
RuntimeError: a components render method must generate and return exactly 1 element or a string
答案 0 :(得分:2)
React.rb组件(如react.js)只能呈现单个根dom元素。
要生成多个元素,您需要将元素包装在div中,例如:
class HelloWorld < React::Component::Base
# stuff
def render
div do
div { "hello" }
div { "goodby" }
end
end
end