CodeZettaInterview Hub

Vue.js · Composition API · Junior · Concept

What is a composable in Vue?

Short Interview Answer

A function starting with use that encapsulates reusable stateful logic via Composition API.

Detailed Explanation

Similar spirit to React hooks but different rules. Return refs/functions. Document side effects.

Example

export function useCounter() {
  const n = ref(0)
  const inc = () => n.value++
  return { n, inc }
}

Did you know this answer?