React 02: JSX


Docs

https://react.dev/learn/writing-markup-with-jsx


What is JSX —

JSX was invented by a team at Facebook/Meta, the same team that created React.

JSX stands for JavaScript XML. JSX is a syntax extension to JavaScript. JSX lets you put markup into JavaScript.


Curly braces for JSX

Curly braces let you "escape back" into JavaScript so that you can embed some variable from your code and display it to the user.

 return (
  <h1>
    {user.name}
  </h1>
 );

 return (
  <img
    className="avatar"
    src={user.imageUrl}
  />
 );

Double Curly braces for JSX

Not a special syntax, but a regular {} object inside the style={ } JSX curly braces.


Conditions in JSX

"if" does not work in JSX.

if else

if wo else


Lists in JavaScript


Last updated