How to use a custom jsx pragma or get rid of import React?
See original GitHub issueQuestion: How to use a custom jsx pragma? OR How to get rid of import * as React from 'react'
at the output when i use a custom jsx processing library?
- I am using a custom library for jsx processing (so i donāt need React package to be installed).
- As a jsx transpiler, the only used plugin is: https://babeljs.io/docs/en/babel-plugin-transform-react-jsx/
- This babel plugin (2) works fine for regular .jsx files (auto-imports the āCustomJsxLibraryā and so onā¦)
- This babel plugin (2) works great with svgr , but there is an extra
import * as React from 'react'
remaining at the beginning of the svg component.
What iāve got so farā¦
Not a very convenient but working method is to use a custom template and delete ${imports}
:
...
return typeScriptTpl.ast`
${interfaces}
function ${componentName}(${props}) {
return ${jsx};
}
${exports}
`
...
Configuration from webpack.config.js
:
...
test: /\.svg$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [
[
'@babel/plugin-transform-react-jsx',
{
runtime: 'automatic',
importSource: 'CustomJsxLibrary'
}
],
]
},
},
{
loader: '@svgr/webpack',
options: {
babel: false,
template: require(path.resolve(__dirname, './template.js')) // without the custom template doesn't work :'(
},
}
]
...
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:6
Top Results From Across the Web
Custom elements in React using a custom JSX pragma
Example using a custom JSX pragma for enable better tooling for custom elements. This project was bootstrapped with Create React App.
Read more >Introducing the New JSX Transform ā React Blog
Remove all unused React imports as a result of upgrading to the new JSX transform. Change all default React imports (i.e. import React...
Read more >Using a custom jsx function - ReScript Forum
It's imported from Theme UI like so: import { jsx } from 'theme-ui' . So basically, I need to figure out how to...
Read more >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
What is JSX pragma? Ā· Using a custom JSX pragma. There are two ways to specify a custom function (and therefore replace React.createElement...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
--jsx-runtime 'automatic'
flag preventimport * as React from "react"
being added šexample:
svgr --icon --typescript --ref --jsx-runtime 'automatic' -d src assets
Iāve done as you suggest š¤¦