Skip to content

Instantly share code, notes, and snippets.

@jkup
Created December 15, 2015 23:47
Show Gist options
  • Save jkup/b2f5e1d742cfd05b6552 to your computer and use it in GitHub Desktop.
Save jkup/b2f5e1d742cfd05b6552 to your computer and use it in GitHub Desktop.
React Question
<div className={(condition) ? 'grid-item Rejection Rejection--width2' : 'grid-item Rejection'}>
// How can I do this without repeating the grid-item and Rejection classes?
// Something like:
//<div className={"grid-item Rejection" if (condition) { "Rejection--width2" }}>
@whmountains
Copy link

+1 for the classnames library. It may seem like a lot to solve just one problem but once you get used to it you'll use it all over the place. It completely eliminates the need for dirty string concatenation.

@WickyNilliams
Copy link

@insin, it's more idiomatic to use an object to hold conditions:

<div className={classNames('grid-item Rejection', { 'Rejection--width2' : condition })}>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment