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

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

Need help with React

Hi,

I'm trying to make a simple react app. I'm getting this annoying msg saying: adjacent jsx elements must be wrapped in an enclosing tag.

I'm not sure what is wrong with this:

function Header(props) {
  return (
    <div className="header">
      <h1>{props.title}</h1>
    </div>
  );
}

Header.propTypes = {
  title: React.PropTypes.string.isRequired,
};

var Application = React.createClass({
  propTypes: {
    title: React.PropTypes.string,
  },

  render: function() {
    return (
      <Header title={this.props.title} />
      <div></div> // it's working fine if I remove this line
    );
  }
});

ReactDOM.render(<Application title="Yatzy" />, document.getElementById("container"));

1 Answer

Jesus Mendoza
Jesus Mendoza
23,289 Points

Hey Henrik,

When you have more than one element in your render function you have to wrap then in an outer div

try:

var Application = React.createClass({
  propTypes: {
    title: React.PropTypes.string,
  },

  render: function() {
    return (
      <div>
         <Header title={this.props.title} />
         <div></div> // its working fine if I remove this line
      </div>
    );
  }
});