drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.61k stars 649 forks source link

[BUG]: useLiveQuery produces 3 re-renders, only needs 2 #3568

Open mphill opened 6 days ago

mphill commented 6 days ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.36.1

What version of drizzle-kit are you using?

0.28.0

Other packages

No response

Describe the Bug

When using live queries, the app re-renders 3 times due to sequential states being set.

These should be combined into a single state, or updatedAt be a ref.

const handleData = (data: any) => { setData(data); setUpdatedAt(new Date()); };

Today, when the screen renders, this is the output:

console.log(data, updatedAt);

[], undefined
[/* data is now populated*], undefined,
[/* data is now populated*], YYYY-MM-DD HH:MM:SS

The second output is where you have records but updatedAt is undefined. This should not occur. You should be able to rely on updatedAt alone to determine if your query is finished.