Search code examples
javascriptreactjsjsxsupabase

REACT - Supabase


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


Solution

  • 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