-
Notifications
You must be signed in to change notification settings - Fork 6
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
useRxData doesn't support findOne #45
Comments
Hey @nirvdrum. Can you please provide a concrete example? Also which versions of rxdb-hooks/rxdb are you using? |
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
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. |
I've run into a type definition error when providing
useRxData
with a query constructor that usesfindOne
. I think the issue is thatfindOne
can returnnull
, whilefind
always returns a value, even if that value is an empty array. The TypeScript error isn't the clearest thing in the world:I can manually query against the collection or just use
find
and unwrap the array in the meanwhile. Please let me know if I can be of any assistance. I couldn't see a simple way to change the return type based on usingfind
vsfindOne
and I don't want to break code on existing users by forcingnull
as a potential return value on all queries. Maybe the solution is a new hook (e.g,useRxDataOne
)?The text was updated successfully, but these errors were encountered: