codex-lv3-may-2025

Level Navigation: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19⚡ 20

Level 6: Select Data and Console Log

Goal: Update the fetch function to actually retrieve data from Supabase.

User Story: As a developer, I want to fetch data from my database so that I can see what meals are stored.


What You’ll Do

Update the handleFetchMeals function to fetch data from Supabase and log it to console.

Instructions

💡 Code Hints

Need help with data fetching? Check out these snippets:

Show Me: updated fetch function
async function handleFetchMeals() {
    console.log("Fetching meals...")
    const result = await supabase.from("potluck_meals").select()
    const data = result.data
    console.log("Fetched data:", data);
    setMeals(data);
}

🔍 Diving Deeper

What is async/await?

Understanding Supabase queries:

const result = await supabase.from("potluck_meals").select()

Error handling pattern:

Always check for errors when working with databases:

if (result.error) {
    console.error('Database error:', result.error);
    return; // Stop execution if there's an error
}

📺 Learn More:

✅ Check

  1. Click the “Fetch Meals” button
  2. Check the browser console - you should see the fetched data
  3. The meals state is updated with the data
  4. No console errors occur
  5. Data is successfully retrieved from Supabase

📚 Vocabulary