React Expressions are one of the core features that make JSX powerful. They allow you to embed dynamic values, logic, and JavaScript computations directly inside your UI markup.
Whenever you see something inside { curly braces } in JSX, that’s a React Expression.
A React Expression is any valid JavaScript expression written inside curly braces {} within JSX.
It tells React:
“Evaluate this JavaScript and insert the result right here in the UI.”
Example:
const name = "Luke";
function App() {
return <h1>Hello, {name}!</h1>;
}
React evaluates {name} and renders:
Hello, Luke!
React allows any JavaScript expression, meaning anything that returns a value.
if, for, switch)React Expressions require expressions, not full statements.
const age = 25;
return <p>I am {age} years old.</p>;
return <p>2 + 5 = {2 + 5}</p>;
function greet() {
return "Welcome to React!";
}
return <h2>{greet()}</h2>;
React doesn’t allow if statements directly in JSX, but you can use ternary expressions.
const isLoggedIn = true;
return (
<div>
{isLoggedIn ? <p>Dashboard</p> : <p>Please Log In</p>}
</div>
);
Great for rendering elements only when a condition is true.
const show = true;
return <div>{show && <p>This is visible</p>}</div>;
If show is false → nothing renders.
const first = "React";
const second = "Expressions";
return <h3>{`${first} ${second}`}</h3>;
Arrays render each item in order (best used for lists with .map()).
const items = ["HTML", "CSS", "JS"];
return <div>{items}</div>;
Output:
HTMLCSSJS
(It prints them without commas unless you format them.)
This is one of the most powerful uses of React expressions:
const languages = ["JavaScript", "TypeScript", "Python"];
return (
<ul>
{languages.map((lang, i) => (
<li key={i}>{lang}</li>
))}
</ul>
);
You cannot display an object directly:
return <p>{user}</p>; // ❌ Error
But you can access its properties:
const user = { name: "Luke", role: "Developer" };
return <p>{user.name} — {user.role}</p>;
JSX is just an expression too!
const message = <strong>React is awesome!</strong>;
return <p>{message}</p>;
You can even use them inside attributes:
const imageUrl = "/avatar.png";
return <img src={imageUrl} alt="Profile" />;
If an expression evaluates to undefined, nothing shows.
const data = undefined;
return <p>{data}</p>; // Renders nothing — no error
Useful for hiding optional values “automatically.”
{if (isAdmin) { <p>Admin</p> }} // Wrong
{isAdmin ? <p>Admin</p> : null}
They allow React to:
They are at the heart of React’s declarative nature.
function Profile({ user }) {
return (
<div>
<h1>{user.name}</h1>
<p>Status: {user.online ? "Online" : "Offline"}</p>
{user.online && <span className="green-dot"></span>}
<h3>Skills</h3>
<ul>
{user.skills.map((skill) => (
<li key={skill}>{skill}</li>
))}
</ul>
</div>
);
}
This demonstrates conditional renders, mappings, and value interpolation—all using React Expressions.
React Expressions let you embed dynamic JavaScript logic inside JSX using {} so your UI updates automatically based on values, functions, and conditions.
Latest tech news and coding tips.
How to Build APIs That Are Easy to Use, Scale, and Maintain Learn on the…
Almost everyone starts learning JavaScript with the wrong expectations. Let's fix them. Download the Codeflare…
Phaser JS is a powerful, open-source HTML5 game development framework used for creating 2D games that…
JavaScript / Node.js Authentication Libraries 1. Passport.js One of the most popular authentication middleware libraries…
Every profession comes with its own set of tools. A carpenter has a toolbox, a…
Every application that stores and manages data relies on a set of basic operations known…