Skip to content

Deprecation: String as dynamic attribute value

Dylan Piercey edited this page Jul 3, 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.

Examples

To conditionally render an attribute

Old:

<div ${test ? "someAttr" : ""}/>

Instead you should use a boolean attribute.

New:

<div someAttr=test/>

To provide multiple dynamic attributes

Old:

<div ${`x=${foo} y="bar"`}/>

Instead you should use spread attributes with an object.

New:

<div ...{ x:foo, y:"bar" }/>
Clone this wiki locally