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 trial

JavaScript React Basics (2018) First Steps in React Embed JavaScript Expressions in JSX

Jesse Dispoto
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jesse Dispoto
Front End Web Development Techdegree Graduate 14,538 Points

Write 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
Ezra Siton
12,644 Points

For 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')
);