Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save AndrewRayCode/b4ac61b6d301e30d37e9 to your computer and use it in GitHub Desktop.

Select an option

Save AndrewRayCode/b4ac61b6d301e30d37e9 to your computer and use it in GitHub Desktop.
Better React ClassSet
// Lets you call classSet with strings *and* objects
// Usage: classSet({a: true, b: false}, 'class1', null, 'class2'); class="a class1 class2"
function classSet() {
var classes = [],
arg, x, key;
for( x = 0; x < arguments.length; x++ ) {
arg = arguments[ x ];
if( typeof arg === 'object' ) {
for( key in arg ) {
if( arg[ key ] ) {
classes.push( key );
}
}
} else if( arg ) {
classes.push( arg );
}
}
return classes.join(' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment