Open kraenhansen opened 1 year ago
I was just testing new way of passing an object with type
& query
as first argument, however it does not work as expected. The rules requires an inline function, not an object with a function inside.
Argh 😞 I don't know how we missed that. This just makes it even more compelling to provide a "class-aware" hook.
The class-aware hook would the best, yes. However if you are introducing already new way of using useQuery, why not to allow to pass function as first argument for now?
Also, due to the way our Realm integration is built, we need to have access to createUseQuery where we pass our own useRealm
.
Example in PR: https://github.com/realm/realm-js/pull/6819
Problem
Users want the simples way possible to query their data, but the current
useObject
anduseQuery
APIs take thetype
as an argument, which could be simplified further.Additionally, the current 3 positional argument layout of
useQuery
means users cannot rely on eslint rules to check for missingdeps
(see https://github.com/realm/realm-js/issues/6259).Solution
A possible solution to both issues above, is to expose functions to generate class / type -aware hooks, which wouldn't require users to pass the
type
argument:One example wrapping
useQuery
(proposed by @kraenhansen)Another example handling both
useQuery
anduseObject
(proposed by @takameyer)A third example where the user just have to pass model classes and the hooks are generated for them (proposed by @bimusiek)
Alternatives
Document and add to examples how users could use
bind
to create derived hooks:How important is this improvement for you?
I would like to have it but have a workaround
Feature would mainly be used with
Atlas Device Sync