0

I am having a problem where I am trying to use an array of data to render a <ul> element. In the code below the console.log's are working fine, but the list items aren't appearing.

<ul className="comments">

              {
              userComments && userComments.comments.data && userComments.comments.data.map(comment =>{
                {console.log("users", comment.user)}
                <li className="wraper" key={comment.id}>
                  <div className="comments-description">
                    <div className="comments-photo">
                      <img src="http://randomuser.me/api/portraits/men/84.jpg" alt="" />
                    </div>
                    <div className="comments_wrapper">
                      <div className="comments_details">
                        <h1>Mike Ross {comment.user}</h1>
                        <span className="days">testa</span>
                      </div>
                      <div className="comments_text">
                          {comment.value}
                
                      </div>
                      <div className="comments_edit-delete">
                        <button className="btn-danger">Delete</button>
                        <button className="btn-success">Edit</button>
                      </div>
                    </div>
                    <div className="comments_line"></div>
                  </div>
                </li>
              })
            }
          
          </ul>

Note: The data looks like this :

enter image description here

What am I doing wrong here?

2 Answers 2

1

Either use:

.map(comment => (<ul> ... </ul>))

or

.map(comment =>({
  return (<ul> ... </ul>)
})
Sign up to request clarification or add additional context in comments.

Comments

1

The brackets are wrong. Wrap your JSX in the round brackets ( )

.map(comment =>( <li> ... </li>)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.