1.0.2 • Published 3 years ago
react-auto-classnames v1.0.2
react-auto-classnames
JSX runtime for applying clsx() to className prop automatically.
NOT a babel plugin.
Installation
npm i react-auto-classnamesUsage
If you use TypeScript, edit your tsconfig.json like:
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "react-auto-classnames",
}
}If you use @babel/preset-react to transform jsx:
// .babelrc / babel.config.json
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "automatic",
"importSource": "react-auto-classnames"
}
]
]
}If you use esbuild (take vite for example):
{
esbuild: {
jsxFactory: 'createElement',
jsxFragment: 'Fragment',
jsxInject: 'import { createElement, Fragment } from \'react-auto-classnames\'',
},
}Then you can write React code like this:
function App() {
return (
<div className={['class-a', 'class-b', {
'class-disabled': disabled,
}]}>
)
}clsx will be used to handle the className prop.