Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to make sure JSX fragment support won't be broken in the future #596

Closed
wants to merge 1 commit into from

Conversation

frenzzy
Copy link
Contributor

@frenzzy frenzzy commented Feb 15, 2018

Looks like Hyperapp already support JSX Fragments, need to just add docs how to use them:

import { h, app } from 'hyperapp'
const Fragment = (_, children) => children

const view = () => (
  <main>
    <Fragment>
      <h1>A</h1>
      <h1>B</h1>
    </Fragment>
  </main>
)

app({}, {}, view, document.body)

console.log(document.body.innerHTML)
// => <main><h1>A</h1><h1>B</h1></main>

Demo: https://codepen.io/frenzzy/pen/WMZMVb?editors=0010

To use <></> syntax, use the following .babelrc config:

{
  "plugins": [
    ["@babel/plugin-transform-react-jsx", { "pragma": "h", "pragmaFrag": "Fragment" }]
  ]
}

and your view may look like this:

const view = () => (
  <main>
    <>
      <h1>A</h1>
      <h1>B</h1>
    </>
  </main>
)

After #591 we will be able to use fragments as a root node:

const view = () => (
  <>
    <h1>A</h1>
    <h1>B</h1>
  </>
)

refs:

Closes #530

@frenzzy frenzzy mentioned this pull request Feb 15, 2018
@codecov
Copy link

codecov bot commented Feb 15, 2018

Codecov Report

Merging #596 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #596   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           1      1           
  Lines         136    136           
  Branches       41     41           
=====================================
  Hits          136    136

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ec9dc6...aacd5d2. Read the comment docs.

@jorgebucaran jorgebucaran added the enhancement New feature or request label Feb 15, 2018
@frenzzy frenzzy changed the title Support JSX fragments Add a test to make sure JSX fragment support won't be broken in the feature Feb 15, 2018
@jorgebucaran jorgebucaran changed the title Add a test to make sure JSX fragment support won't be broken in the feature Add a test to make sure JSX fragment support won't be broken in the future Feb 15, 2018
@jorgebucaran
Copy link
Owner

jorgebucaran commented Feb 15, 2018

Fragments are about treating a tuple or array of elements/nodes as a single keyed item, this is just a clever way to fake it out. The big deal about fragments is, in my opinion, stuff like the following:

<Fragment key={key}><A/><B/></Fragment>

We may have this at some point in the future, but first I need to fix #499.

@jorgebucaran jorgebucaran added invalid This doesn't seem right and removed enhancement New feature or request labels Feb 15, 2018
@sergey-shpak
Copy link
Contributor

@frenzzy hey, looks like this approach doesn't work with lazy components
https://codepen.io/anon/pen/rKRxYd

@Swizz
Copy link
Contributor

Swizz commented Jul 2, 2018

@sergey-shpak Lazy Components like the View root can't return an array. A root element is always required.

See #695

@sergey-shpak
Copy link
Contributor

@Swizz thanks!

@frenzzy frenzzy mentioned this pull request Dec 4, 2018
@jorgebucaran jorgebucaran added the enhancement New feature or request label Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants