Quick start with Effector

Effector is a powerful state manager that offers a fundamentally new approach to data management in applications. Unlike traditional solutions where state is changed directly through actions, Effector uses a reactive and declarative approach.

How to Work with Documentation

Before diving in, itโ€™s worth mentioning that we support llms.txt for using AI assistants like ChatGPT, Claude, Gemini and others. You simply need to share the link in the chat or upload the documentation to an IDE like Cursor.

Currently, the following documents are available:

Additionally, we offer a ChatGPT effector assistant, a repository on DeepWiki, and uploaded documentation on Context7. These resources are designed to help you understand and work more effectively with Effector, with AI-powered support guiding you through the process.

Effector Features

  • Effector is reactive ๐Ÿš€: Effector automatically tracks dependencies and updates all related parts of the application, eliminating the need to manually manage updates.
  • Declarative code ๐Ÿ“: You describe the relationships between data and their transformations, while Effector takes care of how and when to perform these transformations.
  • Predictable testing โœ…: Isolated contexts make testing business logic simple and reliable.
  • Flexible architecture ๐Ÿ—๏ธ: Effector works equally well for both small applications and large enterprise systems.
  • Versatility ๐Ÿ”„: While Effector integrates perfectly with popular frameworks, it can be used in any JavaScript environment.

More about effector core concepts you can read here

Install effector

To get started, install Effector using your favorite package manager:

npm install effector

Creating Your First Store

Now, letโ€™s create a store, which represents a state of your application:

import { createStore } from "effector";

const $counter = createStore(0);

Adding events

Next, letโ€™s create some events, that will update our store when triggered:

import { createEvent } from "effector";

const incremented = createEvent();
const decremented = createEvent();

Connecting Events to Store

And link the events to the store:

// counter.js
import { createEvent, createStore } from "effector";

const $counter = createStore(0);

const incremented = createEvent();
const decremented = createEvent();

$counter.on(incremented, (counter) => counter + 1);
$counter.on(decremented, (counter) => counter - 1);

// and call it somewhere in your app
incremented();
// counter will increase by 1
decremented();
// counter will decrease by -1
decremented();
// counter will decrease by -1

Framework Integration

Installation

If you want to use Effector with a specific framework, youโ€™ll need to install an additional package:

npm install effector effector-react

Usage examples

And use it like this:

import { useUnit } from "effector-react";
import { createEvent, createStore } from "effector";
import { $counter, incremented, decremented } from "./counter.js";

export const Counter = () => {
  const [counter, onIncremented, onDecremented] = useUnit([$counter, incremented, decremented]);
  // or
  const { counter, onIncremented, onDecremented } = useUnit({ $counter, incremented, decremented });
  // or
  const counter = useUnit($counter);
  const onIncremented = useUnit(incremented);
  const onDecremented = useUnit(decremented);

  return (
    <div>
      <h1>Count: {counter}</h1>
      <button onClick={onIncremented}>Increment</button>
      <button onClick={onDecremented}>Decrement</button>
    </div>
  );
};
What about Svelte ?

No additional packages are required to use Effector with Svelte. It works seamlessly with the base Effector package.

Contributors