所有文档都提到了使用类创建组件。我可以创建一个功能组件来利用react钩子吗?如果可以,如何实现?
为了澄清,我只能找到创建基于类的组件的文档,比如
class Example < HyperComponent
render do
DIV { "Example" }
end
end它等同于
class Example extends React.Component {
render() {
return <div>Example</div>
}
}我想重新创建以下内容:
() => {
return <div>Example</div>
}发布于 2019-04-15 22:45:30
不,你不能。有关原因,请参阅https://github.com/hyperstack-org/hyperstack/issues/167。基本答案: Hyperstack DSL已经解决了由功能组件解决的主要问题,添加功能组件(有一些)的缺点超过了任何优点。
请注意,您可以很好地从JS库导入功能组件。
发布于 2019-04-15 21:53:03
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 paramhttps://stackoverflow.com/questions/55690284
复制相似问题