getCurrentInstance

Commons
stable

Asserts that the call is made inside a Vue component setup function and returns the current internal instance. Throws a descriptive [Origam] error when called outside a component context.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

name
required
string
The caller name used in the thrown error message, e.g. "useColor".
message
string
Optional custom error message. Defaults to "must be called from inside a setup function".

API

Return value

The value returned by this util.

The current Vue component internal instance. Never null — throws if the context is absent.

Usage

Examples

Ready-to-paste usage snippets.

Guard a composable to setup context

typescript