Skip to content

Deprecation: String as dynamic attribute value

Taylor Hunt edited this page Aug 2, 2019 · 3 revisions

Passing a string as a value for dynamic attributes is deprecated. The examples below use the old <div ${attrs}/> syntax, but if you’ve run migrations these may use the new ...spread syntax.

Conditionally rendering an attribute

<input ${input.isRequired ? "required" : ""}/>

Instead, use boolean attributes:

<input required=input.isRequired />

ℹ️ Note: For attributes such as aria-expanded and contenteditable that are specced to have meaning when their value is "false", use the literal string "false":

<p aria-expanded="false" contenteditable='false'/>

Providing multiple dynamic attributes

<img ${`src=${markoLogoUrl} alt="Marko"`}/>

Instead, use dynamic spread attributes with an object.

<img ...{ src: markoLogoUrl, alt: "Marko" }/>