On my code I search through a table in a supabase database. Eventually I'll search through using parameters given by user, but right now I'm just trying to retrieve the entire table.
const useSearch = (searchParams) => {
let myObject = getTodos(searchParams).then((data) => {
return data;
});
async function getTodos(searchParams) {
let { data, error } = await supabase.from('deal_finder_deals').select('*');
myObject = data;
return data;
}
return {
searchData: myObject,
}
If I use console.log to check it to see what returns in myObject, it prints out like i want it to.
(2) [{…}, {…}]
0: {id: '0b0173c0-2621-4c69-abc6-b311b6848d8c', city: 'a', state: 'a', zip_code: 2, verified: true, …}
1: {id: '79f5990c-f52f-4c18-a64b-de80a81753a0', city: 'Abilene', state: 'TX', zip_code: 79354, verified: false, …}
length: 2
The issue is I want to import this into another class and it returns as a promise.
let newData = await useSearch({data});
console.log(newData);
The result:
{searchData: Promise}
searchData: Promise
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Array(2)
0: {id: '0b0173c0-2621-4c69-abc6-b311b6848d8c', city: 'a', state: 'a', zip_code: 2, verified: true, …}
1: {id: '79f5990c-f52f-4c18-a64b-de80a81753a0', city: 'Abilene', state: 'TX', zip_code: 79354, verified: false, …}
length: 2
[[Prototype]]: Array(0)
[[Prototype]]: Object
Is there a way I can access the specific data that I want from a promise?