Skip to main content
Deprecated: Use $effect instead. This function only works in legacy mode.
Schedules a callback to run immediately after the component has been updated. The first time the callback runs will be after the initial onMount.

Signature

fn
function
required
A function to run after the component updates.

Usage

Migration to runes

In runes mode, use $effect instead:

Before (legacy mode)

After (runes mode)

Common use case: Auto-scrolling

Before (legacy mode)

After (runes mode)

Key differences

  • afterUpdate only works in legacy mode (non-runes components)
  • $effect is the runes-mode equivalent
  • $effect runs after DOM updates, similar to afterUpdate
  • The first run of afterUpdate happens after onMount
  • $effect tracks dependencies automatically; reference state to react to changes

Notes

  • Only works in legacy mode
  • Runs after every component update
  • First run is after the initial onMount
  • Does not run during server-side rendering