Skip to content
Youngho Chaa cha cha
TwitterHomepage

React Tips

react, tips1 min read

Conditionally join class names

Use classnames: https://github.com/JedWatson/classnames

classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ 'foo-bar': true }); // => 'foo-bar'
classNames({ 'foo-bar': false }); // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'
© 2024 by Youngho Chaa cha cha. All rights reserved.
Theme by LekoArts