toQueryRefs @vuqs/core
Projects the composable into one writable ref per field. Use it to recover the per-field .set/.clear that the grouped values map drops, or to pass a single field around.
Usage
ts
import { codecs, toQueryRefs, useQueryStates } from '@vuqs/core'
const query = useQueryStates({ q: codecs.string, page: codecs.integer.withDefault(1) })
const { q, page } = toQueryRefs(query)
q.set('phone')
page.clear()Type
ts
function toQueryRefs<TSchema extends QueryStateSchema>(query: QueryBindingSource<TSchema>): ToQueryRefs<TSchema>Parameters
query: QueryBindingSource<TSchema>- The
useQueryStatescomposable. For read-only per-field refs over a module'sexplicitValues/defaultsmap, use Vue'stoRefsdirectly.
- The
Return value
refs: ToQueryRefs<TSchema>- One
QueryStateRefper param, with writable.valueplus.set/.clear. A param with a default reads asT, otherwiseT | undefined. Assigningundefinedclears when the ref type includes it;.clear()is available for defaulted params too.
- One
ToQueryRefs
ts
type ToQueryRefs<TSchema extends QueryStateSchema> = {
[Key in keyof TSchema]: QueryStateRef<QueryStateRefValue<TSchema[Key]>, QueryStateRefInput<TSchema[Key]>>
}