Skip to content

Instantly share code, notes, and snippets.

@codingnninja
Created August 4, 2019 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingnninja/f7d79b0281c1399522dc14fb119299b5 to your computer and use it in GitHub Desktop.
Save codingnninja/f7d79b0281c1399522dc14fb119299b5 to your computer and use it in GitHub Desktop.
Food item list
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