Skip to content

Commit f72deca

Browse files
committed
fix duplicate queries with useGet
The useGet utility was running multiple queries when both an `id` and `params` are passed. This update turns on lazy mode by default and performs a single query during setup.
1 parent 06a3e04 commit f72deca

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/composition-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ And here's a look at each individual property:
281281
- `params` is a FeathersJS Params object OR a Composition API `ref` (or `computed`, since they return a `ref` instance) which returns a Params object.
282282
- Unlike the `useFind` utility, `useGet` does not currently have built-in debouncing.
283283
- `queryWhen` must be a `computed` property which returns a `boolean`. It provides a logical separation for preventing API requests apart from `null` in the `id`.
284-
- `lazy`, which is `false` by default, determines if the internal `watch` should fire immediately. Set `lazy: true` and the query will not fire immediately. It will only fire on subsequent changes to the `id` or `params`.
284+
- `lazy`, which is `true` by default, determines if the internal `watch` should fire immediately. By default a single query will be performed, independent of the watchers. Set `lazy: false` and the watchers on the `id` and `params` will fire immediately (currently this will cause duplicate queries to be performed, so it's not recommended).
285285
286286
### Returned Attributes
287287

src/useGet.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function get(options: UseGetOptions): UseGetData {
4646
params: null,
4747
queryWhen: computed((): boolean => true),
4848
local: false,
49-
lazy: false
49+
lazy: true
5050
}
5151
const { model, id, params, queryWhen, local, lazy } = Object.assign(
5252
{},
@@ -127,6 +127,10 @@ export default function get(options: UseGetOptions): UseGetData {
127127
{ lazy }
128128
)
129129

130+
if (lazy) {
131+
get(id, getParams())
132+
}
133+
130134
return {
131135
servicePath,
132136
...toRefs(state),

0 commit comments

Comments
 (0)