markRaw
Overview
Section titled “Overview”The markRaw
function allows you to mark a given value as “raw,” indicating that it should not be converted into a deep ref when using the ref
function. Marking a value as “raw” ensures that specific nested properties or the entire object will remain untracked and not reactive.
Marking a Value as Raw
Section titled “Marking a Value as Raw”To mark a value as raw, you can use the markRaw
function.
import { markRaw } from 'regor'
const myValue = /* Your object here */
// Marking the object as rawconst rawValue = markRaw(myValue)
Parameters
Section titled “Parameters”value
: The object or value you want to mark as raw, preventing it from being deeply converted into a ref object.
Return Value
Section titled “Return Value”- The
markRaw
function returns the same value that you passed as an argument, but with an additional marker indicating it is a raw value.
Implementation Details
Section titled “Implementation Details”- The function sets a marker on the provided value using the
rawSymbol
to indicate that it should not be deeply converted into a ref. - The marked object remains untracked when used with the
ref
function.
Example
Section titled “Example”import { markRaw, ref } from 'regor'
const data = { name: 'Alice', age: 30, rawProperty: markRaw({ nested: 'value' }),}
const myRef = ref(data)
// Changes to rawProperty will not trigger reactivitymyRef().rawProperty.nested = 'updated value'console.log(myRef().rawProperty.nested) // Outputs 'updated value'