1

I have an array that contains as follows. I have successfully mapped the data and put it into the elements. but there are some values I couldn't get correctly. I have added a console.log to figure out the data. data is correct in the array, I want to get the Seats ("A1,B1") in here <h5><small>{seatNos.seats}</small></h5> but nothing is displaying. appreciate any help.

Data array

"data": {
    "userBookings": [
      {
        "transactionId": 6357604,
        "totalAmount": 350,
        "createdAt": "2021-08-05 02:16:48",
        "movieName": "Mortal Kombat",
        "theaterName": "XxX Cinema",
        "showTime": "17:30",
        "refcode": "0016048GIN210805I",
        "bookedSeats": [
          {
            "seatType": "Comfert",
            "seats": "A1,B1",
            "childTickets": 1,
            "totalTickets": 2,
            "bookedDate": "2021-08-05"
          }
        ]
      }
    ]
  },

code

<div className="col-xl-5 col-lg-5 col-md-7 col-sm-7 col-xs-9 col-6" style={{paddingLeft:25}}>
<h5><b>{bookingsData.movieName}</b></h5>
<h5>{bookingsData.theaterName}</h5>
<h5><small>{bookingsData.showTime}</small></h5>

{bookingsData.bookedSeats.map((seatNos) => {
  console.log(seatNos.seats);
   <h5><small>{seatNos.seats}</small></h5>
})}                               
{/* <h5><small>{bookingsData.bookedSeats.seats}</small></h5> */}
</div> 

                           
1
  • 1
    Your map arrow function doesn't return anything (There's no return before the JSX element) Commented Aug 17, 2021 at 12:44

3 Answers 3

1

You need to return element in map, and set key for this element:

{bookingsData.bookedSeats.map((seatNos, index) => {
  console.log(seatNos.seats);
   return <h5 key={index}><small>{seatNos.seats}</small></h5>
})}  
Sign up to request clarification or add additional context in comments.

Comments

1

Your arrow function inside the .map() doesn't return a value. You need a return before the JSX:

{bookingsData.bookedSeats.map((seatNos) => {
  console.log(seatNos.seats);
  return <h5><small>{seatNos.seats}</small></h5>
})}  

Or to use the implicit return arrow function syntax (Either round brackets, or no brackets: () => () or () => returnedValue)

{bookingsData.bookedSeats.map((seatNos) => <h5>
  <small>{seatNos.seats}</small>
</h5>)}  

Comments

1

This is because you forgot the return


 array.map((item) => {
      return (
        <p>{item.value}</p>
      )
    })                            

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.