How to call a function within another function?
I would like to get an id from another function, instead of providing the id via args. My use case is that I want to get all users from a group using the current users activeGroupId.
This query gives me the Id that I need:
Now, I don't know how to use it in my query to get all members. This is the current code, where the groupId is an empty string, which is the one I want to get replaced by the output of getActiveSpace:
Can you point me in towards a ressource or help me what I missed to get it to work? There might also be a simpler solution.
4 Replies
You can’t call a query from another query - if you ever need to, you can instead split out the code inside of the function you want to reuse so you can reuse it in multiple queries.
In this case, you could create a regular function that is used by both getActiveSpace and getGroupMembers queries.
All of that said, the code in your getActiveSpace query is so straightforward, I would just write the user query in both of your query functions.
Okay thank you! I tend to overcomplicate things as I often think that it will effect the performance, but Convex handles everything really well!
For sure. Premature optimization is an even greater temptation than usual with Convex in my experience, it’s faster than you’d expect. I’ve learned to just get things working and go back to see what needs improving.
That is a good approach. Thanks for the advice. I'll get cracking with the app. 🙂