I am using a serverless frame work and tRPC for routes. When I make a call to the backend it will initially be undefined and then return the appropriate data. I am not sure if my call is wrong on the frontend or if there is an issue with retrieving data from the backend. I have tried adding awaits, but nothing worked.
route call
const t = initTRPC.create();
const appRouter = t.router({
Todos: t.procedure
.query(() => {
// console.log(Todo.list())
return Todo.list()
})
})
db query
export function list() {
return PG.DB.selectFrom("todo")
.selectAll()
.orderBy("todoID")
.execute()
}
frontend
function IndexPage() {
const todoList = trpc.Todos.useQuery()?.data;
console.log("--------", todoList)
if (!todoList) return <div>Loading...</div>;
return (
<div>
<table className="table table-bordered">
<thead>
<tr>
<th className="th-sm">task</th>
</tr>
</thead>
<tbody>
{todoList.map((todo) => {
return (
<>
<tr key={todo?.todoID}>
<td>{todo.task}</td>
</tr>
</>
);
})}
</tbody>
</table>
</div>
);
}