# svelte/require-store-callbacks-use-set-param

store callbacks must use set param

# 📖 Rule Details

This rule disallows if readable / writable store’s setter function doesn’t use set parameter.
This rule doesn’t check derived store. Therefore if you set a updated value asynchronously, please don’t forget to use set function.

<script>
  /* eslint svelte/require-store-callbacks-use-set-param: "error" */
  import { readable, writable, derived } from 'svelte/store';

  /** ✓ GOOD  */
  readable(null, (set) => {
    set(new Date());
    const interval = setInterval(() => set(new Date()), 1000);
    return () => clearInterval(interval);
  });

  // `set` is unused but this rule doesn't report.
  // For that, please use `no-unused-vars` rule.
  // refer: https://eslint.org/docs/latest/rules/no-unused-vars
  readable(false, (set) => true);

  writable(null, (set) => {
    set(1);
    return () => {
      /* no more subscribers */
    };
  });

  writable(false, (set) => true);

  derived(a, ($a) => $a * 2);
  derived(
    a,
    ($a, set) => {
      setTimeout(() => set($a), 1000);
    },
    'one moment...'
  );

  /** ✗ BAD  */
  readable(false, () => true);
  readable(false, (foo) => true);

  writable(false, () => true);
  writable(false, (foo) => true);
</script>

# 🔧 Options

Nothing.

# 📚 Further Reading

# 🚀 Version

This rule was introduced in eslint-plugin-svelte v2.12.0

# 🔍 Implementation