0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LWC_メモ01_if:true 廃棄される?

Posted at

salesforceの公式サイトで、以下の記述があります。

lwc:if|elseif ディレクティブは、テンプレートに {property} をバインドし、そのデータが真値 (truthy) と偽値 (falsy) のいずれであるかに応じて DOM 要素を削除および挿入します。
従来の if:true および if:false ディレクティブは今後廃止と削除が予定されているため、現在は推奨されません。コードが今後の変更に対応できるように、lwc:if|elseif|else 条件ディレクティブを代わりに使用することをお勧めします。

if:trueの使い例:

<template>
    <template if:true={testVariable}>
        show true
    </template>
    <template if:false={testVariable}>
        show false
    </template>
</template>

lwc:if|elseif|elsetrueの使い例:

    <h1 lwc:if={renderedWrapper.section1}>
        show section1
    </h1>
    <h1 lwc:elseif={renderedWrapper.section2}>
        show section2
    </h1>
    <h1 lwc:elseif={renderedWrapper.section3}>
        show section3
    </h1>
    <h1 lwc:elseif={renderedWrapper.section4}>
        show section4
    </h1>

どっちのほうが使いやすいかは個人の判断と思いますが、
現場でよく見えるのは、if:true
今後if:trueが廃止とされるなら、今からコーディングする場合、lwc:if使うのは将来的にメンテナンス作業が軽減されると思いますね。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?