call method
EffectScope
call({})
Creates an effect scope hook for managing effect lifecycles.
An effect scope allows you to group related effects together and dispose them all at once. Useful for component-based architectures.
Parameters:
fn: Optional function to execute within the scope contextkeys: Optional keys for hook memoizationdebug: Optional debug options
Returns: An EffectScope for managing effect lifecycles
Example:
Widget build(BuildContext context) {
useEffectScope(fn: (scope) {
scope.run(() {
final signal = Signal(0);
Effect(() => print(signal.value));
onScopeDispose(() => print('Scope cleaned up'));
});
});
return Text('Component with scoped effects');
}
Implementation
EffectScope call({
void Function(EffectScope scope)? fn,
bool detach = false,
List<Object?>? keys,
JoltDebugOption? debug,
}) {
return use(JoltEffectHook(() {
final scope = EffectScope(detach: detach, debug: debug);
if (fn != null) {
scope.run(() => fn(scope));
}
return scope;
}, keys: keys));
}