question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Using jsx pragma, is there a way to use the <></> Fragment shorthand?

See original GitHub issue
  • emotion version: v10
  • react version: 16.7.0 / latest

Relevant code:

/** @jsx jsx */
import { jsx, css } from '@emotion/core';

export default function App() {
  return (
    <>
      <div css={css`color: red;`}>Test</div>
      <div>Fragment</div>
    </>
  );
}

What you did:

Attempted to use the Fragment shorthand enabled in Babel 7 <></>, caused an error using the jsx pragma.

What happened:

Error thrown: React is undefined

Reproduction:

https://codesandbox.io/s/p7r4l19p2m

Problem description:

N/A

Suggested solution:

Additional documentation on the docs site if it is possible, or document that the fragment shorthand is unsupported.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
Andaristcommented, Jan 7, 2019

Fragments have different pragma - https://babeljs.io/docs/en/next/babel-plugin-transform-react-jsx.html#custom-1 . As it’s not of our interest, you should just rely on default one with React - therefore you should add:

import * as React from 'react'

to your file when using Fragment shorthand.

4reactions
jhoffmcdcommented, Mar 26, 2019

This hardly seems like a solution. Are we just to live with a hacky way of wanting to use both CSS prop and a React Fragment shorthand in the same file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flow errors on <React.Fragment> or <></>, but not <Fragment>
I would like to use the <></> Fragment shorthand syntax, and this issue is stopping me from doing that for now. When I...
Read more >
Emotion JSX Pragma and Fragment Shorthand Bug?
CodeSandbox is an online editor tailored for web applications.
Read more >
Fragments - React
A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding...
Read more >
<> or <React.Fragment> ? : r/reactjs - Reddit
You can transpile JSX to something other than React quite easily. Just set the pragma in this Babel plugin and it will use...
Read more >
Readme — cljsx 1.0.0 - cljdoc
There are other macros with pragmas bound to other JSX compatible frameworks. inferno> bound to inferno-create-element/createElement and inferno/Fragment .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found