1

All of the documentation refers to creating components using classes. Can I make a functional component in order to leverage react hooks, and if so, how?

To clarify, I can only find documentation for creation a class based component like

class Example < HyperComponent
  render do
    DIV { "Example" }
  end
end

Which would be equivelent to

class Example extends React.Component {
  render() {
    return <div>Example</div>
  }
}

I want to recreate the following:

() => {
  return <div>Example</div>
}
Cereal
  • 3,699
  • 2
  • 23
  • 36

2 Answers2

1

No, you cannot. See https://github.com/hyperstack-org/hyperstack/issues/167 for why. Basic answer: the Hyperstack DSL already solves the major issues solved by functional components, and the negatives of adding functional components (there are some) then outweigh any advantages.

Note that you can import functional components from JS libraries just fine.

Mitch VanDuyn
  • 2,838
  • 1
  • 22
  • 29
0
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
BarrieH
  • 373
  • 3
  • 11
  • Hi, not quite what I'm looking for. Functional components are a little different from class-based components and allow the use of hooks, which libraries are moving towards: https://reactjs.org/docs/hooks-intro.html – Cereal Apr 15 '19 at 14:06