• An enhanced version of effect from @vue/reactivity, adding support for a cleanup function.


    Registers the given function to track reactive updates.

    The given function will be run once immediately. Every time any reactive property that's accessed within it gets updated, the function will run again.

    Example

    const count = ref(0)
    effect(() => {
    console.log(count.value)
    return () => console.log('cleanup')
    })
    count.value++

    Returns

    A runner that can be used to control the effect after creation.

    Parameters

    • fn: (() => void | CleanupFn)

      The function that will track reactive updates. The return value from this function will be used as a cleanup function.

        • (): void | CleanupFn
        • Returns void | CleanupFn

    • Optional options: ReactiveEffectOptions

      Allows to control the effect's behaviour.

    Returns ReactiveEffectRunner<any>

Generated using TypeDoc