@gluonjs/reactivity


@gluonjs/reactivity / packages/reactivity/src / effectScope

Function: effectScope()

effectScope(options?): EffectScope

Parameters

options?

boolean | EffectScopeOptions

Returns

EffectScope

Example

Create an EffectScope that records effects and cleanup callbacks executed inside scope.run():

ts
import {
  EffectScope,
  effect,
  effectScope,
  getCurrentScope,
  onScopeDispose,
  ref,
  type EffectScopeOptions,
} from '@gluonjs/reactivity';

const options: EffectScopeOptions = {
  detached: true,
  onError: ({ error }) => console.error(error),
};
const scope: EffectScope = effectScope(options);
const count = ref(0);
scope.run(() => {
  console.log(getCurrentScope() === scope);
  effect(() => console.log(count.value));
  onScopeDispose(() => console.log('scope disposed'));
});
count.value = 1;
scope.stop();