0 day streak
javascript / beginner
Snippet

The tick Lifecycle Helper

Svelte batches DOM updates for performance. The tick function returns a promise that resolves once any pending state changes have been applied to the DOM.

snippet.js
javascript
1
2
3
4
5
6
7
import { tick } from 'svelte';
async function updateAndFocus() {
text = 'Updated!';
await tick();
console.log('The DOM is now in sync');
}
svelte
Breakdown
1
import { tick } from 'svelte';
Imports the tick function from the Svelte core package.
2
await tick();
Pauses function execution until Svelte has finished updating the DOM after the previous state change.