@pinia/plugin-debounce

Debounce any action in your pinia 🍍 store!

Usage no npm install needed!

<script type="module">
  import piniaPluginDebounce from 'https://cdn.skypack.dev/@pinia/plugin-debounce';
</script>

README

Pinia logo Pinia Debounce

npm package build status

Debounce any action in your pinia 🍍 store!

This is also a very good example of how to create a pinia plugin and how to type it.

Installation

npm install @pinia/plugin-debounce

You also need to use a debounce function like lodash.debounce or ts-debounce

Usage

import { debounce } from 'ts-debounce'
import { PiniaDebounce } from '@pinia/plugin-debounce'

// Pass the plugin to your application's pinia plugin
pinia.use(PiniaDebounce(debounce))

You can then use a debounce option in your stores:

defineStore('id', {
  actions: {
    someSearch() {
      // ...
    },
  },
  debounce: {
    // debounce all `someSearch` calls by 300ms
    someSearch: 300,
  },
})

License

MIT