You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -154,6 +154,46 @@ Each model gets these mutation hooks:
154
154
155
155
## Advanced Features
156
156
157
+
### Working with Reactive Parameters
158
+
159
+
Pinia Colada automatically tracks reactive dependencies in your queries. When using reactive values (refs, computed), wrap your query arguments in a getter function:
authorId: userId.value, // Unwrap refs inside the getter
171
+
deletedAt: includeDeleted.value?undefined:null
172
+
},
173
+
}))
174
+
175
+
// When userId or includeDeleted changes, the query automatically re-runs!
176
+
```
177
+
178
+
**Why use a getter function?**
179
+
180
+
The getter function `() => ({...})` allows Pinia Colada to track when your reactive values change and automatically re-fetch the query. Inside the getter, unwrap refs with `.value`.
181
+
182
+
**Alternative patterns:**
183
+
184
+
```typescript
185
+
// Using computed (also works)
186
+
const queryArgs =computed(() => ({
187
+
where: { authorId: userId.value }
188
+
}))
189
+
const { data } =queries.post.useFindMany(queryArgs)
190
+
191
+
// Static queries (no reactivity needed)
192
+
const { data } =queries.post.useFindMany({
193
+
where: { published: true } // No getter needed for static values
194
+
})
195
+
```
196
+
157
197
### Optimistic Updates
158
198
159
199
Optimistic updates allow the UI to update immediately before the server responds:
0 commit comments