Comments (2)
Hey @nirvdrum. Can you please provide a concrete example? Also which versions of rxdb-hooks/rxdb are you using?
from rxdb-hooks.
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)
- types for database? HOT 1
- useRxData and component re-render HOT 5
- useRxData and component re-render HOT 2
- useRxDocument type does not support numeric id HOT 3
- useRxCollection returns null the first time it is called? HOT 2
- useRxCollection does not support lazy collection initialization HOT 7
- Wrong paths in package.json HOT 2
- Database type doesn't match type expected by Provider HOT 2
- useRxData doesn't support findByIds HOT 2
- Electron remote breaks hooks
- Is RXDB v12 supported? HOT 2
- Support RxDB 12
- How to handle multiple databases? HOT 2
- Question: useRXCollection not able to notice deletion and recreation of collection in one sitting HOT 1
- New functionality: collection.count HOT 1
- rxdb 13 breaks lazy collection creation HOT 1
- hooks stuck loading on local but work on production HOT 10
- useRxData doesn't return result and keeps fetching HOT 2
- How to combine multiple collection queries into a single hook?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxdb-hooks.