vue-lynx / shallowReactive

Function: shallowReactive()

function shallowReactive<T>(target): ShallowReactive<T>

Shallow version of reactive.

Unlike reactive, there is no deep conversion: only root-level properties are reactive for a shallow reactive object. Property values are stored and exposed as-is - this also means properties with ref values will not be automatically unwrapped.

Type Parameters

Type Parameter
T extends object

Parameters

ParameterTypeDescription
targetTThe source object.

Returns

ShallowReactive<T>

Example

const state = shallowReactive({
  foo: 1,
  nested: {
    bar: 2
  }
})

// mutating state's own properties is reactive
state.foo++

// ...but does not convert nested objects
isReactive(state.nested) // false

// NOT reactive
state.nested.bar++

See

https://vuejs.org/api/reactivity-advanced.html#shallowreactive

Defined in

node_modules/.pnpm/@vue+reactivity@3.5.30/node_modules/@vue/reactivity/dist/reactivity.d.ts:79