skip to Main Content

I am Running this piece of code:

import { useEffect, useState } from 'react';
import { createClient } from '@supabase/supabase-js';

const supabase = createClient("https://<project>.supabase.co", '<anon-key>');

const GetBalance = () => {
    const [data, setData] = useState([]);

    useEffect(() => {
        getData();
    }, []);

    async function getData() {
        const { udata } = await supabase.from("balances").select();
        setData(udata);
    }

    return (
        <ul>
            {data.map(transactions => (
                <li key={transactions.balance}>{transactions.balance}</li>
            ))}
        </ul>
    )
}

export default GetBalance;

it responds with ‘Cannot read properties of undefined (reading ‘map’).’
I have disables RLS on supabase and the table does include data and is not empty.

Is this a syntactical error in my code? or have I configured my supabase project incorrectly?
I have searched online and disables RLS however it has done nothing

I was trying to connect to my database on supabase but it would connect but not display data. I then disables RLS and it spits out this error

2

Answers


  1. Chosen as BEST ANSWER

    I figured that if i change the line

    const { udata } = await supabase.from("balances").select();

    to

    const { data: udata } = await supabase.from("balances").select();

    it would work as it was a variable issue with the nameing


  2. The first step would be to console.log ‘data’ to see if you are getting any. Seems like the ‘data’ is undefined. You could also try writing this:

    {data?.map((transactions) => (
        <li key={transactions.balance}>{transactions.balance}</li>
    ))}
    

    Also, I believe you intentionally replaced the actual project id and key values in the line below with and , but just making sure:

    const supabase = createClient("https://<project>.supabase.co", '<anon-key>');. Of course, these should be values you get from your project dashboard.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search