Skip to content

Instantly share code, notes, and snippets.

@electerious
Created January 21, 2017 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electerious/99d08574044a68b1794e1e69274fccc5 to your computer and use it in GitHub Desktop.
Save electerious/99d08574044a68b1794e1e69274fccc5 to your computer and use it in GitHub Desktop.
Conditionally convert the keys of an object to a string of class names
const toClassString = (obj) => Object.keys(obj).filter((key) => obj[key]===true).join(' ').trim()
@electerious
Copy link
Author

Example:

const classes = {
	enter: true,
	entering: true,
	leave: false,
	leaving: false
}

toClassString(classes) // 'enter entering'

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