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

SpreadChildren #67

Closed
NekR opened this issue Nov 9, 2016 · 1 comment
Closed

SpreadChildren #67

NekR opened this issue Nov 9, 2016 · 1 comment

Comments

@NekR
Copy link

NekR commented Nov 9, 2016

I would like to propose this syntax:

const items = [
  <li />,
  <li />,
  // ...
];

<ul>
  <li />
  { ...items }
  <li />
</ul>

For React this would transform into this:

// Simplified version
React.createElement('ul', null, <li />, ...items, <li />);

Why? Because some times in conditions it's needed to use an array with statically (never changing) defined JSX items. I think it's reasonable since workaround was proposed but just without JSX syntax: facebook/react#2816 (comment)

@sebmarkbage
Copy link
Contributor

This is already part of the JSX spec. See JSXChildExpression. https://github.com/facebook/jsx

However, it is not allowed as part of the React implementation of JSX. The best practice is to use nested arrays to ensure that different child sets have unique keys.

The issue of putting static items in an array and not wanting to assign keys to them could be solved by a fragment syntax for example. This could mark them as static for the key warning.

const items = <><li /><li /></>;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants