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.

Document using site-wide JSX pragma configuration

See original GitHub issue
{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "throwIfNamespace": false, // defaults to true
        "runtime": "automatic", // defaults to classic
        "importSource": "theme-ui" // defaults to react
      }
    ]
  ]
}

https://babeljs.io/docs/en/babel-plugin-transform-react-jsx

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:26 (16 by maintainers)

github_iconTop GitHub Comments

5reactions
hasparuscommented, Dec 22, 2020

okay @adamsoffer, I mostly use sx and always TypeScript 😄 Feel free to @ me when you encounter problems like this.

Thanks for this comment! That’s actually something we need to cover in the docs.


Previously, sx was added to global JSX types, so it was super easy to conflict with other libraries. Right now, we’re exporting JSX namespace, and TypeScript adds sx prop when it sees the pragma comment.

That’s nice, because we’re not polluting global JSX namespace anymore, but this means that if you configure Babel to support sx everywhere you need to add sx manually to React types.

You need to add the following to one of your files.

// To add `css` if you're using it somewhere
/// <reference types="@emotion/react/types/css-prop" />

import {} from 'react'
import { ThemeUIStyleObject } from '@theme-ui/core' // or 'theme-ui'

declare module 'react' {
  interface Attributes {
    sx?: ThemeUIStyleObject
  }
}

We’ll add an entry point similar to @emotion/react/types/css-prop before a stable release, so it’s going to be a bit more convenient to use.

2reactions
flo-schcommented, Apr 29, 2021

I could try something, will PR on the pragma page

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSX Pragma - Theme UI
JSX Pragma. Theme UI uses custom JSX functions and JSX import source comments to allow you to style elements with values from your...
Read more >
What is JSX pragma? - Gatsby
Theme UI uses a custom JSX pragma to add support for Theme UI's sx prop, which is used to style elements by referencing...
Read more >
Pragma — Zuul documentation
It is used to alter how the configuration is processed while loading. A pragma item only affects the current file. The same file...
Read more >
What does JSX compile to? · Stupidly Simple
In TypeScript, this transform makes use of the jsxFactory and jsxFragmentFactory configuration options. jsxFactory can be changed on a per-file ...
Read more >
HTML Standard
3 Semantics, structure, and APIs of HTML documents ... client-side scripts or server-side site-wide scripts to process using the data-*="" attributes.
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