Skip to content

Add Fragment to @stencil/core #1151

Closed
Closed
@NEO97online

Description

@NEO97online

Stencil version:

 @stencil/core@0.13.2

I'm submitting a:

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
Rendering multiple elements requires either a wrapping div or returning an array. Returning an array avoids rendering an unwanted <div>, but array format with JSX is hard to read and work with, especially in larger components.

Expected behavior:
Just like React, you could wrap multiple elements in a <Fragment> tag.

Steps to reproduce:
Without fragment:

render() {
  return [
    <div>My first element</div>,
    <div>
        <span>Another element</span>
    </div>,
    <div>And another</div>
  ]
}

Related code:
With fragment:

render() {
  return (
    <Fragment>
      <div>My first element</div>
      <div>
        <span>Another element</span>
      </div>
      <div>And another</div>
    </Fragment>
  )
}

Other information:

This is an extremely simple feature to add, I'm just not sure where it should go in the stencil repository.
The working Fragment code is literally just this one line:

export const Fragment = (props, children) => children

Or without ES6:

export function Fragment(props, children) {
  return children
}

Used as a JSX element, this simply renders the children without rendering an arbitrary wrapping element.

I made a package here to provide this feature, but it would be fantastic if it were available in @stencil/core. People coming from React will love this.

If someone can advise me where in the repo to add this code, I would be happy to make the PR myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ionitron: stale issueThis issue has not seen any activity for a long period of time

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions