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

Adjacent JSX elements must be wrapped in an enclosing tag

function Application(){
  return(
      <h1>Users Table</h1>
       <form>
         <input type="text" />
         <input type="submit" value="+" />
       </form>
       <div id="users">
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
       </div>
  );
}

ReactDOM.render(<Application />,document.getElementById('container'));

I tried to wrap form in div but it doesn't seem to work for me...

1 Answer

andren
andren
28,538 Points

When using JSX you can only return a single element. In your solution there are three elements (h1, form and div) that are adjacent to each other. The way to solve this is to wrap all of them in a div like this:

function Application(){
  return(
  <div>
      <h1>Users Table</h1>
       <form>
         <input type="text" />
         <input type="submit" value="+" />
       </form>
       <div id="users">
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
         <li className="user">Ashish Mehra <button>Edit</button><button>Delete</button></li>
       </div>
   </div>
  );
}

Thanks I forget this ;-p