Created
August 4, 2019 15:29
-
-
Save codingnninja/f7d79b0281c1399522dc14fb119299b5 to your computer and use it in GitHub Desktop.
Food item list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const FoodItemList = (props) => { | |
return ( | |
<table className="table table-bordered"> | |
<thead> | |
<tr> | |
<th>Id</th> | |
<th>Food</th> | |
<th>Cost</th> | |
<th>Actions</th> | |
</tr> | |
</thead> | |
<tbody> | |
{ | |
props.foodItems.length > 0 ? ( | |
props.foodItems.map((foodItem) => ( | |
<tr key={foodItem.id}> | |
<td>{ foodItem.id }</td> | |
<td>{ foodItem.food }</td> | |
<td>{ foodItem.cost }</td> | |
<td> | |
<button className="btn btn-primary ml-2" onClick={() => props.editFoodItem(foodItem) }>Edit</button> | |
<button className="btn btn-danger ml-2" onClick={() => props.deleteFoodItem(foodItem.id) }>Delete</button> | |
<button className="btn btn-info ml-2" onClick={() => props.boughtFoodItem(foodItem) }> | |
{ foodItem.status ? 'bought' : 'pending' } | |
</button> | |
</td> | |
</tr> | |
) | |
) | |
) : ( | |
<tr> | |
<td colSpan={3}>No food for a lazy man</td> | |
</tr> | |
) | |
} | |
</tbody> | |
</table> | |
); | |
} | |
export default FoodItemList; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment