Skip to content

Latest commit

 

History

History
executable file
·
65 lines (49 loc) · 819 Bytes

README.md

File metadata and controls

executable file
·
65 lines (49 loc) · 819 Bytes

babel-plugin-jsx-classnames

transform

<div className={arrayOrObjectExpr}></div>

to

<div className={classNames(arrayOrObjectExpr)}></div>

why

with react

<button className={`${active ? 'btn-active' : ''} ${disabled ? 'btn-disabled' : ''}`}>
</button>
<button
  className={classNames({
    'btn-active': active,
    'btn-disabled': disabled,
  })}>
</button>

with babel-plugin-jsx-classnames

<button
  className={{
    'btn-active': active,
    'btn-disabled': disabled,
  }}>
</button>

usage

npm i babel-plugin-jsx-classnames --save-dev
{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    ...
    "jsx-classnames"
  ]
}