useToggleScope
Commons
stable
Conditionally activates a Vue effectScope driven by a reactive boolean source. When the source turns true the scope starts (running the provided callback inside it); when it turns false the scope is stopped and discarded. The scope is also stopped on parent scope dispose.
API
Signature
Full TypeScript signature sourced from the composable file.
useToggleScope is a low-level primitive used internally by useVModel, useValidation, and other composables that need conditional effect trees. Prefer those higher-level composables for typical use cases.
API
Parameters
Input parameters accepted by this composable.
- sourcerequiredWatchSource<boolean>
- Reactive boolean source (ref, computed, or getter). When it evaluates to true the scope is started; when false the scope is stopped.
- fnrequired(reset: () => void) => void
- Callback run inside the new effectScope. Receives a `reset()` function that can be called from inside the scope to stop the current scope and immediately restart it — useful for subscriptions that need to re-initialise when an inner condition changes.
Usage
Examples
Ready-to-paste usage snippets.
Run a watcher only while a panel is open
Reset the scope when a sub-condition changes