Skip to content

Instantly share code, notes, and snippets.

@RobinMalfait
Created November 15, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinMalfait/93c3ef90da203316629be28585b5e418 to your computer and use it in GitHub Desktop.
Save RobinMalfait/93c3ef90da203316629be28585b5e418 to your computer and use it in GitHub Desktop.
classNames util example
const classNames = (...classes) => classes.filter(Boolean).join(' ');
// No need to default to an empty string as className
function Switch({on, className, ...props}) {
return (
<div className="toggle">
<input
className="toggle-input"
type="checkbox"
/>
<button
className={classNames(
className,
'toggle-btn',
on && 'toggle-btn-on',
!on && 'toggle-btn-off'
)}
{...props}
/>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment