| Level Navigation: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19⚡ | 20 |
Goal: Refresh the meals list after inserting a new meal.
User Story: As a user, I want to see my new meal appear in the list immediately after submitting the form so that I can confirm it was added.
Update your handleAddMeal function to refresh the meals list after inserting.
handleAddMeal function to refresh the meals list after insertingsupabase.from("potluck_meals").select()setMeals(data)Need help with refreshing the list? Check out these snippets:
async function handleAddMeal(event){
event.preventDefault()
console.log("handle add meal submitted")
const mealName = event.target.elements.mealName.value
const guestName = event.target.elements.guestName.value
const serves = event.target.elements.serves.value
const kindOfDish = event.target.elements.kindOfDish.value
const newMeal = {
meal_name: mealName,
guest_name: guestName,
serves: parseInt(serves),
kind_of_dish: kindOfDish
}
console.log(newMeal)
// Insert the new meal
await supabase.from("potluck_meals").insert(newMeal)
// Refresh the meals list
const response = await supabase.from("potluck_meals").select()
const data = response.data
setMeals(data)
}