Effect

const effectStore = defineStore(({ reactive, effect }) => {
  const count = reactive(0);
  const logEffect = reactive<string | undefined>(undefined);

  effect(() => {
    logEffect.set(`effect was called with count:${count.value}`);
  });

  const increment = () => count.set((prev) => prev + 1);

  return { count, logEffect, increment };
});

Result

render: 0

count: effect was called with count: 0

ON THIS PAGE