23
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSXのclassNameのクラスを動的に追加する

Last updated at Posted at 2018-01-09

公開中ならpublished, 非公開ならunpublishedをclassNameに追加するというイメージ。

実装

配列内で三項演算子を使って処理し、そのあとでjoin()を使って連結することで実装できた。

className={[
  'post',
  isPublished ? 'published' : 'unpublished'
].join(' ')}

参考

How to add multiple classes to a ReactJS Component

23
16
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?