Data Fetching Composable Advice
We have an Organization entity in our app, and each organization has related Events. We’re expecting to reuse this fetching logic across multiple parts of our app.
Fetching the organization data alone is straightforward and nicely encapsulated:
Usage in a page:
Where we’re stuck is how best to fetch and structure related event data. These events are tied to the organization.
One idea was to extend the composable like this:
Then use it like this:
This works, but by spreading the
So I’m wondering:
- Is this an acceptable approach?
- Should we separate event logic into its own composable (e.g.,
- Is there a clean way to preserve the thenable behavior while extending the returned object?
Any best practices, patterns, or anti-patterns to consider would be much appreciated!
Fetching the organization data alone is straightforward and nicely encapsulated:
Usage in a page:
Where we’re stuck is how best to fetch and structure related event data. These events are tied to the organization.
One idea was to extend the composable like this:
Then use it like this:
This works, but by spreading the
orgResponse, we lose the “thenable” behavior of useFetch. We’d like to keep the ability to await useOrganization(id) in page-level usage.So I’m wondering:
- Is this an acceptable approach?
- Should we separate event logic into its own composable (e.g.,
useOrganizationEvents(id))?- Is there a clean way to preserve the thenable behavior while extending the returned object?
Any best practices, patterns, or anti-patterns to consider would be much appreciated!
