0Pricing
Sveltejs Academy · Lesson

beforeUpdate and afterUpdate

Hook into the update cycle to inspect or modify the DOM before and after reactive changes.

When They Run

beforeUpdate runs before reactive updates flush to DOM; afterUpdate runs immediately after.

Use Cases

Use them to read DOM measurements before changes and adjust scroll position after.

All lessons in this course

  1. onMount: Running After Render
  2. onDestroy: Cleanup
  3. beforeUpdate and afterUpdate
  4. tick(): Waiting for DOM Updates
← Back to Sveltejs Academy