
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Custom React JSX Runtime to support arrays and objects in className prop natively.

clsx-react - JSX Super Power for classNameStop importing clsx or classnames manually.
clsx-react is a zero dependency, super tiny, custom React JSX runtime that natively supports arrays and objects in the className prop. It automatically applies clsx logic at the runtime level, keeping your code clean and your imports empty.
You need conditional class names in your React components, but importing and using clsx or classnames everywhere leads to repetitive boilerplate code.
// ❌ Old way: Boilerplate everywhere
import clsx from 'clsx'; // or classnames
export const Button = ({ active, disabled }) => (
<button className={clsx('btn', { 'btn-active': active, 'btn-disabled': disabled })}>Click me</button>
);
No more imports or boilerplate. Just use arrays and objects directly in className. Strings still work as usual.
// ✅ New way: Zero imports, native syntax
export const Button = ({ active, disabled }) => (
<button className={['btn', { 'btn-active': active, 'btn-disabled': disabled }]}>Click me</button>
);
npm install clsx-react
# or
yarn add clsx-react
# or
pnpm add clsx-react
Note: Requires
react>= 17.0.0.
To make this work, you need to tell your compiler to use this package as the JSX Import Source instead of the default react. Let me guide you through the setup for various environments.
tsconfig.json) / JavaScript (jsconfig.json) - RecommendedThis handles both the compilation and the type definitions (so TS won't complain about arrays in className).
{
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "clsx-react"
}
}
vite.config.ts) / EsbuildIf you are using Vite, you can set it explicitly in the config:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
esbuild: {
jsxImportSource: 'clsx-react',
},
});
Next.js usually respects tsconfig.json or jsconfig.json. Ensure your compilerOptions are set as shown in step 1.
If you are using Babel, you can set the jsxImportSource in your Babel config:
{
"presets": [
[
"@babel/preset-react",
{
"runtime": "automatic",
"importSource": "clsx-react"
}
]
]
}
Once configured, you can use className just like you would use the clsx function arguments.
<div className={{ hidden: isHidden, flex: isFlex }}>...</div>
<div className={['text-lg', 'font-bold', isError && 'text-red-500']}>...</div>
<div className={['p-4', { 'bg-gray-100': !dark }, ['shadow-md', 'rounded']]}>...</div>
<div className="just-a-string">...</div>
This package wraps the standard react/jsx-runtime and react/jsx-dev-runtime. It intercepts the creation of every JSX element:
className prop exists.className is not a string (array or object).clsx.It adds negligible overhead (bytes) and eliminates the need to manually import and call class utilities in every single component file.
This package includes a global augmentation for React.HTMLAttributes. Once you set "jsxImportSource": "clsx-react" in your tsconfig.json, TypeScript will automatically understand that className accepts arrays and objects. No extra .d.ts configuration needed!
See Code of Conduct, Contributing, and Security Policy.
MIT License © 2026 Zsolt Tövis
If you find this project useful, please consider sponsoring me on GitHub, PayPal, or give the repo a star.
FAQs
Custom React JSX Runtime to support arrays and objects in className prop natively.
The npm package clsx-react receives a total of 6 weekly downloads. As such, clsx-react popularity was classified as not popular.
We found that clsx-react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.