Get Started

Svelte Use is a collection of utility functions.

Installation

NPM

npm i @svelte-use/core
# yarn add @svelte-use/core
# pnpm i @svelte-use/core

Usage Example

Simply importing the functions you need from @svelte-use/core

<script>
  import { usePreferredDark, useLocalStorage } from '@svelte-use/core'

  // is user prefers dark theme
  const isDark = usePreferredDark()

  // persist state in localStorage
  const storage = useLocalStorage({
    'my-storage',
    {
      name: 'Apple',
      color: 'red'
    }
  })
</script>

Refer to functions list for more details.

WARNING

We use the writableas element binding a lot in usage example.

const el = writable()
<div bind:this={$el}></div>