Vue3: how to factor out a `watch` statement in composition API

Viewed 46

I have the following chunk of code that's duplicated across multiple components:

    const mint = ref<string>('');
    watch(() => payload.mintPk, async (newVal) => {
      if (newVal.length >= 32) {
        mint.value = await prettifyMint(payload.mintPk);
      }
    });
    prettifyMint(payload.mintPk)
      .then((m) => {
        mint.value = m;
      });

I can't figure out how to factor it out into a standalone function that can be re-used across components. Any advice?

1 Answers
Related