Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJesse Dispoto
Front End Web Development Techdegree Graduate 14,538 PointsWrite the const variable names inside the header tag instead of copying and pasting the h1 and p elements?
While rewriting our code to use JSX, Gil manually copies and pastes the h1 and p elements inside the header JSX element like so
const header = (
<header>
<h1> My First React element</h1>;
<p> I just learned how to create a react node and render it into the dom</p>;
</header>
);
This seems somewhat counter intuitive. Is there a way were we can simply write the variable names inside the header tag, like so?
const header = (
<header>
title
desc
</header>
);
1 Answer
Ezra Siton
12,644 PointsFor other users:
const title = "my title";
const desc = "my desc";
const header = (
<header>
<h1>{title}</h1>
<p>{desc}</p>
</header>
);
ReactDOM.render(
header,
document.getElementById('root')
);
Jesse Dispoto
Front End Web Development Techdegree Graduate 14,538 PointsJesse Dispoto
Front End Web Development Techdegree Graduate 14,538 Pointsanswered my own question... assign the variables to plain js strings and then put the variables inside the respective HTML tags within the {}