-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useLiveQuery
needs a default value.
#544
Comments
I think it's ok to be more verbose when you need that option. If we default to |
I think any default value should be explicit. It's useful, when you want to, to be able to distinguish between empty results and no results yet. |
|
The pglite/packages/pglite/src/live/interface.ts Lines 29 to 51 in 0c7454d
pglite/packages/pglite-react/src/hooks.ts Lines 101 to 112 in 0c7454d
although not a option arg one. Maybe we should add that. |
Currently, useLiveQuery returns
undefined
until the initial query has returned. This leads to a bunch ofif results !=== undefined
checks in your component code.For example:
Now, if you look at
useState
, it avoids this by supporting a default value:I propose the ergonomic improvement of supporting a default value with
useLiveQuery
:Using a third positional argument for it is slightly tricky with query parameters (hence cherry picking an example of a query that uses parameters), because then you need to specify the query parameters arg even if not using them. I guess an alternative would be a
{default: value}
option (more explicit but also more verbose).The text was updated successfully, but these errors were encountered: