---
source: https://iinventedlight.com/library/notes/vue-composables.md
title: "Vue composables reuse stateful logic with the Composition API"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0, text only (vuejs/docs); MIT (vuejs/core); prose restates cited source lines in own words"
license_family: vue-docs-ccby
attribution: "Summary by iinventedlight (AI-assisted). Sources: Vue.js docs, Composables, CC BY 4.0, text only (vuejs/docs); Vue.js core, runtime-core apiLifecycle, MIT (vuejs/core). Notices: Vue.js documentation (vuejs/docs): Copyright (c) 2019-present, Yuxi (Evan) You and Vue documentation contributors; CC BY 4.0, text only (https://raw.githubusercontent.com/vuejs/docs/main/LICENSE). Vue.js core (vuejs/core): Copyright (c) 2018-present, Yuxi (Evan) You and Vue contributors; MIT (https://raw.githubusercontent.com/vuejs/core/main/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-10
status: published
approved_by: "Cole Withington, 2026-11-10 10:08 PT, Librarian chat widget t33s2: \"Yes, publish all 25 Django and Vue drafts\""
checked_on: 2026-11-10
as_of: 2026-11-10
confidence: medium
untested: "No Vue app was run for this note; only the fetched documentation and source files were read."
category: coding-references
topic_area: "code-web: Vue composables"
tags: [vue, composables, composition-api, lifecycle]
client: Librarian
sources:
  - id: S1
    title: "Composables"
    publisher: Vue.js docs
    url: https://vuejs.org/guide/reusability/composables.html
    accessed: 2026-11-10
    license: "CC BY 4.0"
  - id: S2
    title: "runtime-core apiLifecycle"
    publisher: Vue.js core source
    url: https://github.com/vuejs/core/blob/main/packages/runtime-core/src/apiLifecycle.ts
    accessed: 2026-11-10
    license: "MIT"
---
# Vue composables reuse stateful logic with the Composition API

**Answer:** In Vue, a composable is a function that uses the Composition API to encapsulate and reuse stateful logic — state that changes over time, not a stateless formatter.

## Side effects

A composable may perform side effects such as adding DOM event listeners or fetching data. The guide's rule is to register those in post-mount hooks such as `onMounted()` (especially under SSR) and to clean them up in `onUnmounted()`.

## Why setup() matters

Those hooks are lifecycle injection APIs. `onMounted` is created with `createHook` from the `MOUNTED` hook. `onUnmounted` is created with `createHook` from the `UNMOUNTED` hook. Lifecycle injection APIs can only be used during execution of `setup()`. Call a composable during `setup()` so those hooks can be registered.

## See also

- [vue-reactivity-fundamentals](https://iinventedlight.com/library/notes/vue-reactivity-fundamentals/)
- [vue-lifecycle-hooks](https://iinventedlight.com/library/notes/vue-lifecycle-hooks/)

## Claims

- id: C1
  claim: A composable is a function that uses the Composition API.
  source: S1
  evidence: "a \"composable\" is a function that leverages Vue's Composition API"

- id: C2
  claim: Composables should clean up side effects in onUnmounted().
  source: S1
  evidence: "Remember to clean up side effects in `onUnmounted()`."

- id: C3
  claim: Lifecycle injection APIs can only be used during setup().
  source: S2
  evidence: "Lifecycle injection APIs can only be used during execution of setup()."

- id: C4
  claim: onMounted is the injected MOUNTED hook.
  source: S2
  evidence: "export const onMounted: CreateHook = createHook(LifecycleHooks.MOUNTED)"

## Sources

- [S1] Composables. Vue.js docs. https://vuejs.org/guide/reusability/composables.html . License: CC BY 4.0. Accessed 2026-11-10.

- [S2] runtime-core apiLifecycle. Vue.js core source. https://github.com/vuejs/core/blob/main/packages/runtime-core/src/apiLifecycle.ts . License: MIT. Accessed 2026-11-10.


License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Vue.js documentation (vuejs/docs): Copyright (c) 2019-present, Yuxi (Evan) You and Vue documentation contributors; CC BY 4.0, text only (https://raw.githubusercontent.com/vuejs/docs/main/LICENSE). Vue.js core (vuejs/core): Copyright (c) 2018-present, Yuxi (Evan) You and Vue contributors; MIT (https://raw.githubusercontent.com/vuejs/core/main/LICENSE). Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
