Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React Basics 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,537 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,631 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')
);