Pay attention
This documentation is for the as yet unreleased version of effector Spacewatch 23.0.

useStore

useStore(store)

A hook function, which subscribes to watcher, that observes changes in the current readonly` store, so when recording results, the component will update automatically. You can mutate the store value only via createEvent.

Designed for vue 3

Arguments

  1. store (Store)

Returns

readonly(State)

Example

import { createStore, createApi } from "effector";
import { useStore } from "effector-vue/composition";

const $counter = createStore(0);

const { increment, decrement } = createApi($counter, {
  increment: (state) => state + 1,
  decrement: (state) => state - 1,
});

export default {
  setup() {
    const counter = useStore($counter);

    return {
      counter,
      increment,
      decrement,
    };
  },
};
Contributors