You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Users want the simples way possible to query their data, but the current useObject and useQuery APIs take the type 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 missing deps (see #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:
exportconstusePersons=createQueryHook<Person>("Person");exportconstuseDogs=createQueryHook<Dog>("Dog");// ... and so on, one for every class in their schema// `createQueryHook` could even have an overload for class-based models, like some of our other APIs:exportconstusePersons=createQueryHook(Person);// And in a consuming component:consttwenty=20;constteenagers=usePersons(persons=>persons.filtered("age < $0",twenty),[twenty]);
Another example handling both useQuery and useObject (proposed by @takameyer)
import{createModelHooks}from'@realm/react';// orimport{createModelHooks}from'../MyRealmContext';classPersonextendRealm.Object{}//some class based modelconst[usePersonById,usePerson]=createModelHooks(Person);
A third example where the user just have to pass model classes and the hooks are generated for them (proposed by @bimusiek)
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.
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: #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 #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
The text was updated successfully, but these errors were encountered: