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
Colocating meaning they’re stored in the same file?
In the same file structure, can be same file or separate files same directory
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
Yeah I'm not sure it's worth doing but might end up taking a whack at it
By Components you mean React Client Components?
Right
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.
Hmm true - I'd expect typescript to make noise if I didn't import export properly too, so maybe not so brittle