StoicBuilder

HandbookI the LudusArrays

Ithe Ludus, Read code

Arrays

1 min readUpdated 28 November

In plain words

An array is an ordered list of values, like posts in a feed or items in a cart, where each item has a numbered position starting at 0.

Where you see it

Square brackets are the giveaway. Chirp's feed is an array of posts, and posts[0] is the one at the top. When you select rows from Supabase you get an array back, even if it holds one row or none.

src/pages/Feed.tsxbrowser
const posts = [ { id: 1, author: "maya", text: "Shipped Quill v1" }, { id: 2, author: "leo", text: "Coffee first" },]; posts[0].author; // "maya"posts.length; // 2
Positions start at 0. length counts from 1.

What goes wrong

  1. Reading [1] to get the first item

    The first item lives at [0]. Asking for [1] gets the second, so your "latest post" banner shows yesterday's.

  2. Expecting one row and getting a list

    A Supabase select returns an array, so data.name is undefined when you meant data[0].name. Add .single() when you want exactly one row.

  3. Treating an empty array as missing

    An empty array still counts as true, so if (posts) passes with no posts at all. Check posts.length === 0 to show an empty state.

    if (!posts) showEmptyMessage(); // never runs for []

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
Wherever this page reads a list, handle three cases: no items, one item and many. Show an empty state when the array is empty, and note which queries return an array and which return a single row.

Quick check

Sign in to earn +10 XP for it

Your Chirp feed is empty, yet the "No posts yet" message never appears. The code says if (!posts). Why?

Got a prompt that touches arrays?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.