unref
Overview
Section titled “Overview”The unref
function allows you to safely retrieve the original value from a ref object if the given value is a ref, or it simply returns the value itself if it’s not a ref.
Unwrapping a Ref
Section titled “Unwrapping a Ref”To safely retrieve the original value from a ref or non-ref value, you can use the unref
function.
import { unref } from 'regor'
const myValue = /* Your ref or non-ref value here */
const unwrappedValue = unref(myValue)
Parameters
Section titled “Parameters”value
: The value you want to unwrap. It can be a ref object or a non-ref value.
Return Value
Section titled “Return Value”- The
unref
function returns the original value if the providedvalue
is a ref. Ifvalue
is not a ref, it returns the samevalue
itself.
Example
Section titled “Example”import { ref, unref } from 'regor'
const myRef = ref('Hello, Regor!')
// Unwrapping a ref valueconst unwrappedValue = unref(myRef)console.log(unwrappedValue) // Outputs 'Hello, Regor!'
const nonRefValue = 'This is not a ref.'
// Unwrapping a non-ref value (no change)const sameValue = unref(nonRefValue)console.log(sameValue) // Outputs 'This is not a ref.'