Introduction
SvelteUse is a collection of Svelte 5 utilities based on runes. It is assumed that you are at least somewhat familiar with the runes system.
You can use it with SvelteKit and with Svelte-only apps as it doesn't rely on Sveltekit-specific features.
Installation
Usage
TIP
Refer to the documentation of each function to see how to use it and examples.
You can simply import the utility you need from @sv-use/core
and use it.
An example using a state that is persisted via local storage :
Best Practices
Cleanup
Some utilities produce side-effects, such as invoking an event listener. By
default, they are automatically cleaned up in an onDestroy
hook.
However, this requires the function to be called in the component initialization lifecycle.
To opt out of this, every utility that produces a side-effect returns a cleanup function that can be used to clean it manually.
Here is an example using handleEventListener :
And how to cleanup manually :