Skip to content

Instantly share code, notes, and snippets.

@sen0rxol0
Last active June 20, 2017 15:53
Show Gist options
  • Save sen0rxol0/7eaead61b03f3d1c5b1efc73c1786e02 to your computer and use it in GitHub Desktop.
Save sen0rxol0/7eaead61b03f3d1c5b1efc73c1786e02 to your computer and use it in GitHub Desktop.
Better conditional className in react with classnames and template literals
import React from 'react';
import classNames from 'classnames';
export default function Button() {
let btnClasses = classNames({
'btn--large': true,
'btn--disabled': false
});
return (
<button className={`btn btn--simple ${btnClasses}`} ></button>
//using template literals to concatenation
//it will render to <button class='btn btn--simple btn--large'></button>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment