1

I am getting the following error while adding two extra button in the list using React.js.

Error:

./src/TodoItems.js
Syntax error: Adjacent JSX elements must be wrapped in an enclosing tag (10:46)
   8 |  
   9 |   createTasks(item) {
> 10 |     return <li key={item.key}>{item.text}</li><a href="" class="button bg_green">Edit</a><a href=""class="button bg_red">Delete</a>
     |                                               ^
  11 |   }
  12 |  
  13 |   render() {

I am explaining my code below.

import React, { Component } from "react";
class TodoItems extends Component {
  constructor(props, context) {
    super(props, context);

    this.createTasks = this.createTasks.bind(this);
  }

  createTasks(item) {
    return <li key={item.key}>{item.text}</li><a href="" class="button bg_green">Edit</a><a href=""class="button bg_red">Delete</a>
  }

  render() {
    var todoEntries = this.props.entries;
    var listItems = todoEntries.map(this.createTasks);

    return (
      <ul className="theList">
          {listItems}
      </ul>
    );
  }
};

export default TodoItems;

Here I am adding two button with the list i.e-li element and getting the above error. I need to resolve those error and add two button there.

  • 1
    createTasks must return a parent element, like
  • {item.text} EditDelete
  • or wrap it under a div ... check this below : https://stackblitz.com/edit/react-ypqryi – Jayavel Feb 22 '18 at 07:19
  • Yes you are right. –  Feb 22 '18 at 07:23
  • Possible duplicate [React - expressions must have one parent element?](https://stackoverflow.com/questions/48886726/react-expressions-must-have-one-parent-element) – Mayank Shukla Feb 22 '18 at 07:24
  • Glad, you got what you need @subhra . For finding out this type ff errors check with some online IDE's for react like stackblitz.com, this will show an error immediately before posting on stackoverflow. You could solve it urself – Jayavel Feb 22 '18 at 07:29