Hyperapp: Question about jsx and props.children

Created on 27 Feb 2017  路  3Comments  路  Source: jorgebucaran/hyperapp

In react when using jsx, you can nest components by using props.children.

Is this possible with hyperapp? I've tried doing it in my views but it isn't working the way I'd expect it to.

For example, this does not work as intended:

const { h, app } = hyperapp
/** @jsx h */

const Foo = ({ children }) => (
  <div>
    hello {children}
  </div>
)


app({
  view: _ => <Foo>world</Foo>
})

/* view should return <div> hello world </div> */

Most helpful comment

@traducer In react when using jsx, you can nest components by using props.children.

In HyperApp, the signature of a component function is as follows: (data, children).

If there are no children, an empty array is passed.
[[Source](https://github.com/hyperapp/hyperapp/blob/master/src/h.js#L14)]

Perhaps you want this?

const Foo = (props, children) => 
  <div>
    hello {children}
  </div>

All 3 comments

@traducer In react when using jsx, you can nest components by using props.children.

In HyperApp, the signature of a component function is as follows: (data, children).

If there are no children, an empty array is passed.
[[Source](https://github.com/hyperapp/hyperapp/blob/master/src/h.js#L14)]

Perhaps you want this?

const Foo = (props, children) => 
  <div>
    hello {children}
  </div>

@jbucaran, awesome explanation, thank you.

I used choo quite a bit, so being able to use different virtual dom builders is nice.

@traducer Choo is very nice too. Thanks! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SkaterDad picture SkaterDad  路  3Comments

dmitrykurmanov picture dmitrykurmanov  路  3Comments

jamen picture jamen  路  4Comments

dmitrykurmanov picture dmitrykurmanov  路  4Comments

VictorWinberg picture VictorWinberg  路  3Comments