Skip to content

nullableRef

Creates a Vue ref that starts as null unless an initial value is provided. Use it for refs that are intentionally empty during setup but should keep a concrete value type after assignment.

Importing

ts
import { nullableRef } from '@almighty-shogun/common';

Usage

ts
import { nullableRef } from '@almighty-shogun/common';

const selectedId = nullableRef<number>();
const count = nullableRef(123);

selectedId.value = 42;
count.value = null;

Parameters

value?: Undefinable<T>
Initial value for the ref.
Default: null

Returns

A Vue ref whose value can be null.

Uses

Type signature

ts
declare function nullableRef<T = never>(
    value?: Undefinable<T>
): Ref<Nullable<T>>;

All packages are released under the MIT License.