--- category: Reactivity --- # reactivePick Reactively pick fields from a reactive object. ## Usage ### Basic Usage ```ts import { reactivePick } from '@vueuse/core' const obj = reactive({ x: 0, y: 0, elementX: 0, elementY: 0, }) const picked = reactivePick(obj, 'x', 'elementX') // { x: number, elementX: number } ``` ### Predicate Usage ```ts import { reactivePick } from '@vueuse/core' const source = reactive({ foo: 'foo', bar: 'bar', baz: 'baz', qux: true, }) const state = reactivePick(source, (value, key) => key !== 'bar' && value !== true) // { foo: string, baz: string } source.qux = false // { foo: string, baz: string, qux: boolean } ``` ### Scenarios #### Selectively passing props to child ```vue ``` #### Selectively wrap reactive object Instead of doing this ```ts import { useElementBounding } from '@vueuse/core' import { reactive } from 'vue' const { height, width } = useElementBounding() // object of refs const size = reactive({ height, width }) ``` Now we can just have this ```ts import { reactivePick, useElementBounding } from '@vueuse/core' const size = reactivePick(useElementBounding(), 'height', 'width') ``` ## Type Declarations ```ts export type ReactivePickReturn = { [S in K]: UnwrapRef } export type ReactivePickPredicate = ( value: T[keyof T], key: keyof T, ) => boolean export declare function reactivePick( obj: T, ...keys: (K | K[])[] ): ReactivePickReturn export declare function reactivePick( obj: T, predicate: ReactivePickPredicate, ): ReactivePickReturn ```