Giter VIP home page Giter VIP logo

Comments (2)

cvara avatar cvara commented on August 17, 2024

Hey @nirvdrum. Can you please provide a concrete example? Also which versions of rxdb-hooks/rxdb are you using?

from rxdb-hooks.

nirvdrum avatar nirvdrum commented on August 17, 2024

Hi @cvara. Thanks for taking a look. I'm using rxdb-hooks 4.0.1.

What I was trying to do was:

const todosQuery = (collection: any) => {
    collection.findByIds(todoChain.todo_ids)
};
const { result: todoMap, isFetching } = useRxData('todos', todosQuery);

Generally I use type annotations so I don't get back a generic RxDocument or RxCollection, but I couldn't find a signature that would work. So, here I'm just using the any type and letting the type inference engine handle things up to the useRxData call. The TypeScript error I received was:

TS2769: No overload matches this call.
  Overload 1 of 3, '(collectionName: string, queryConstructor: QueryConstructor<unknown> | undefined): RxQueryResultDoc<unknown>', gave the following error.
    Argument of type '(collection: any) => void' is not assignable to parameter of type 'QueryConstructor<unknown>'.
      Type 'void' is not assignable to type 'RxQuery<unknown, RxDocumentBase<unknown, {}>> | RxQuery<unknown, RxDocumentBase<unknown, {}>[]> | undefined'.
  Overload 2 of 3, '(collectionName: string, queryConstructor: QueryConstructor<unknown> | undefined, options?: Override<UseRxQueryOptions, { json?: false | undefined; }> | undefined): RxQueryResultDoc<...>', gave the following error.
    Argument of type '(collection: any) => void' is not assignable to parameter of type 'QueryConstructor<unknown>'.
  Overload 3 of 3, '(collectionName: string, queryConstructor: QueryConstructor<unknown> | undefined, options?: Override<UseRxQueryOptions, { json: true; }> | undefined): RxQueryResultJSON<...>', gave the following error.
    Argument of type '(collection: any) => void' is not assignable to parameter of type 'QueryConstructor<unknown>'.

What I've ended up doing is:

const todosCollection = useRxCollection<TodoDoc>('todos');

useEffect(() => {
  const subscription = todosCollection?.findByIds$(todoIds).subscribe((todos) => {
      // todos is an ES6 Map<string, TodoDocument>.
      console.log("todo map", todos.get("some_id"));
  });

  return () => subscription?.unsubscribe();
}, [todoIds, todosCollection]);

While this works, I really like how rxdb-hooks handles all of the annoying subscribe and unsubscribe logic along with return any "loading" state.

Please let me know if you need anymore info.

from rxdb-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.