erquhart
erquhart14mo ago

Colocating convex functions with components

Considering doing something like this, curious if there's any prior art or known gotchas. I have a framework built up around the database now that handles a lot of the things necessary to keep data interactions simple and predictable, so the actual api is becoming pretty focused on specific components. Good idea / bad idea?
8 Replies
jamwt
jamwt14mo ago
Colocating meaning they’re stored in the same file?
erquhart
erquhartOP14mo ago
In the same file structure, can be same file or separate files same directory
jamwt
jamwt14mo ago
gotcha. unfortunately, cannot be helpful here. I'm not aware of a project doing this, but that doesn't mean it hasn't been done... 😄 it definitely has pros and cons, and I think it's a pretty interesting idea for certain projects
erquhart
erquhartOP14mo ago
Yeah I'm not sure it's worth doing but might end up taking a whack at it
Michal Srb
Michal Srb14mo ago
By Components you mean React Client Components?
erquhart
erquhartOP14mo ago
Right
ian
ian14mo ago
You can export the functions from the component files and import & re-export them in the convex/ directory. However, if you forget to re-export, then they won't be deployed (feels a bit brittle). You could write your components in the convex/ file which feels odd to me.
erquhart
erquhartOP14mo ago
Hmm true - I'd expect typescript to make noise if I didn't import export properly too, so maybe not so brittle

Did you find this page helpful?