Theme-ui: How to use React fragments?

Created on 22 Jul 2019  路  2Comments  路  Source: system-ui/theme-ui

Using just the pragma results in a build failure in a ReferenceError, "React is not defined". However, importing React triggers the eslint no-unused-vars rule.

/** @jsx jsx */
// import React from 'react';
import { jsx } from 'theme-ui'
import Button from './Button'

const Page = props => {
  return (
    <>
      <Button>Hello</Button>
    </>
  )
}

export default Page

Reproduction: https://codesandbox.io/s/theme-ui-starter-tdy3y

All 2 comments

You'll need to import React to use fragments. If your linter is complaining, either disable it with a comment or you can use <React.Fragment> instead of the shorthand

I wondered if that was the case. Found a related issue here https://github.com/emotion-js/emotion/issues/1156 though there doesn't seem to be a nice resolve. Will leave for now, thanks.

Was this page helpful?
0 / 5 - 0 ratings