所有文档都涉及使用类创建组件。我可以制作一个功能组件以利用反应钩子,如果是这样,怎么做?
为了澄清,我只能找到创建基于类的组件的文档
class Example < HyperComponent
render do
DIV { "Example" }
end
end
这相当于
class Example extends React.Component {
render() {
return <div>Example</div>
}
}
我想重新创建以下内容:
() => {
return <div>Example</div>
}
你不能。请参阅https://github.com/hyperstack-org/hyperstack/issues/167了解原因。基本答案:Hyperstack DSL已经解决了功能组件解决的主要问题,添加功能组件(有一些)的负面影响超过了任何优势。
请注意,您可以从JS库中导入功能组件。
example = Example().as_node
# then you can do
example.render
# or anything else you want with the example object
Another(example_component: example) # to pass it as a param