Embedding Expressions

Embedding Expressions

JSX allows you to embed expressions between tags by surrounding the expressions with curly braces ({ }).

1
2
3
var a = <div>
  {["foo", "bar"].map(i => <span>{i / 2}</span>)}
</div>

The above code will result in an error since you cannot divide a string by a number. The output, when using the preserve option, looks like:

1
2
3
var a = <div>
  {["foo", "bar"].map(function (i) { return <span>{i / 2}</span>; })}
</div>
doc_TypeScript
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.