= []
private readonly users = createQueriesController(this, () => ({
queries: this.userIds.map((id) => ({
queryKey: ['user', id],
queryFn: () => fetchUserById(id),
})),
}))
render() {
const userQueries = this.users()
return html`
${userQueries.map((query, index) => {
if (query.isPending) return html`- Loading...
`
if (query.isError) return html`- Error loading user
`
return html`- ${this.userIds[index]}: ${query.data.name}
`
})}
`
}
}
```
The order of the results matches the order of the input queries.
## Combining Results
Use `combine` when a component wants one derived value instead of an array of query results:
```ts
private readonly dashboard = createQueriesController(this, {
queries: [
{ queryKey: ['stats'], queryFn: fetchStats },
{ queryKey: ['projects'], queryFn: fetchProjects },
],
combine: ([stats, projects]) => ({
activeUsers: stats.data?.activeUsers ?? 0,
projects: projects.data ?? [],
isPending: stats.isPending || projects.isPending,
isError: stats.isError || projects.isError,
}),
})
```
```ts
render() {
const dashboard = this.dashboard()
if (dashboard.isPending) return html`Loading...`
if (dashboard.isError) return html`Unable to load dashboard`
return html`
Total projects: ${dashboard.projects.length}
Active users: ${dashboard.activeUsers}
`
}
```
Having the same query key more than once in the `queries` array can cause those entries to share cached data. Deduplicate repeated keys first if each rendered row needs independent query state.