Effector Vue Bindings

23.1.1 · active · verified Sun Apr 19

Effector-vue provides official Vue bindings for the Effector state management library, enabling reactive integration of Effector's "algebraic effects" based state logic within Vue applications. It is currently stable at version 23.1.1, with releases typically aligning with major `effector` updates to ensure compatibility and leverage new features. The library's core strength lies in offering a thin, efficient layer to connect Effector's immutable stores and events with Vue's reactivity system, primarily through the `useUnit` hook for the Composition API. This approach offers a powerful, declarative data flow paradigm, emphasizing explicit data transformations and event handling as an alternative to traditional Flux-like patterns. It supports both Vue 3 Composition API and Options API, facilitating diverse project setups and migrations from older Vue versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic reactive state management using `effector-vue` with Vue 3's Composition API. It sets up an Effector store and event, then uses `useUnit` to bind them to a Vue component, showcasing how input changes update derived state.

import {createStore, createEvent} from 'effector'
import {useUnit} from 'effector-vue/composition'
import { defineComponent, h } from 'vue';

export const inputText = createEvent<string>()
export const $text = createStore<string>('').on(inputText, (_, text) => text)
export const $size = $text.map(text => text.length)

const App = defineComponent({
  setup() {
    const text = useUnit($text)
    const size = useUnit($size)
    const handleTextChange = useUnit(inputText)

    return () =>
      h('form', [
        h('input', {
          type: 'text',
          onInput: (e: Event) => handleTextChange((e.target as HTMLInputElement).value),
          value: text.value
        }),
        h('p', `Length: ${size.value}`)
      ])
  }
});

// To run in a browser or test environment (example setup)
if (typeof window !== 'undefined') {
  import { createApp } from 'vue';
  const app = createApp(App);
  app.mount('#app');
}

view raw JSON →