I have a data store in state which needs to be displayed in a tabular format in UI using React. I am using a map function to display the data. I am able to display the data but the header is being displayed after each row as they are iterated in a loop.
Please let me know how can i display the output in tabular format with header being displayed only once?
return method code in React:-
return (
<div>
<br />
<input
type="submit"
class="btn btn-info btn-sm"
value="Create Itinerary"
onClick={this.callItinAPI}
/>
<br />
<br />
{this.state.ItinData.map((item) => (
<div>
<table id="DisplayRequest">
<tr>
<th>TripName</th>
<th>Booking ID</th>
<th>Start Date</th>
<th>End Date</th>
</tr>
<tr>
<td>{item.Itinerary.TripName._text}</td>
<td>{item.Itinerary.Bookings.Booking.RecordLocator._text}</td>
<td>{item.Itinerary.StartDateLocal._text}</td>
<td>{item.Itinerary.EndDateLocal._text}</td>
</tr>
</table>
</div>
))}
</div>
);
Expected output:- Table header to displayed only once followed by all the data rows
