Quiz
1. Which statement about Shared State Across Component Instances is accurate?
2. When reviewing Shared State Across Component Instances, which point must hold?
3. What does a module-scoped ref inside a composable module create?
4. Why create user state per SSR request?
Flashcards
Question
What is Shared State Across Component Instances?
Click to reveal answer
Answer
Decide when a composable should create state per call or share one instance.
Question
Shared State Across Component Instances: why it matters
Click to reveal answer
Answer
Refs declared at module scope inside a composable act as a single shared singleton store.
Question
Shared State Across Component Instances: key detail
Click to reveal answer
Answer
Refs declared inside the function body give every caller an independent copy of the state.
Question
Shared State Across Component Instances: practical note
Click to reveal answer
Answer
Shared composable state resets only on full page reload, not on component unmount.
Question
What is the effect of declaring a ref at module scope in a composable module?
Click to reveal answer
Answer
Module-scope state is shared across callers and persists independently of individual component lifetimes.
Revision Notes
Key Takeaways
- 1. Refs declared at module scope inside a composable act as a single shared singleton store.
- 2. Refs declared inside the function body give every caller an independent copy of the state.
- 3. Shared composable state resets only on full page reload, not on component unmount.
Interview Tips
- • Explain Shared State Across Component Instances with one concrete example from real vue work, not a textbook restatement.
- • Discuss the trade-off: when Shared State Across Component Instances helps and when a lighter approach wins.
- • Place Shared State Across Component Instances inside the Lifecycles and Composables phase — interviewers check that you see the progression, not isolated facts.
Cheat Sheet
Shared State Across Component Instances Cheat Sheet
Phase: Lifecycles and Composables | Level: advanced
Key points:
- Refs declared at module scope inside a composable act as a single shared singleton store.
- Refs declared inside the function body give every caller an independent copy of the state.
- Shared composable state resets only on full page reload, not on component unmount.
- Move truly shared state into Pinia when it must be inspected or reset by devtools.
Tags: vue, composables, state
Continue Learning
Before You Start
- No prerequisites listed.