From the course: React Foundations by Pearson
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Evaluating JavaScript expressions in JSX - React.js Tutorial
From the course: React Foundations by Pearson
Evaluating JavaScript expressions in JSX
In the example just now, I showed some simple JSX which had some text. It's also possible to embed JavaScript expressions in the middle of your JSX content, which can make your output parameterized effectively. What you need to do is you need to enclose the JavaScript expressions inside curly brackets. So here's a simple example. I've got an array, data, and it contains a few items, Swansea shirt, Cardiff shirt, Lamborghini. So here is a chunk of, well, this bit here is XML. And inside the XML, you can have JavaScript inside curly brackets. So the curly brackets basically tells Babel to treat it as a JavaScript expression and to evaluate it as a JavaScript expression. So Babel is constantly kind of flipping from JavaScript mode to XML mode. So when Babel starts parsing the code, it'll think, well, this is JavaScript, JavaScript, JavaScript, JavaScript, JavaScript, JavaScript, JavaScript. And then as soon as it sees the angle bracket, it's now thinking XML. So this is now considered to…
Contents
-
-
-
-
-
-
(Locked)
Learning objectives1m 21s
-
(Locked)
Getting started with JSX6m 40s
-
(Locked)
Creating a simple user interface via JSX13m 27s
-
(Locked)
Evaluating JavaScript expressions in JSX7m 4s
-
(Locked)
Data-driven JSX10m 52s
-
(Locked)
Passing properties to a component via JSX12m 56s
-
(Locked)
Additional JSX techniques16m 44s
-
(Locked)
Lab: using JSX9m 47s
-
(Locked)
Lab solution: Using JSX5m 24s
-
(Locked)
-
-
-
-
-
-
-
-
-