Top Related Projects
🐻 Bear necessities for state management in React
The official, opinionated, batteries-included toolset for efficient Redux development
Quick Overview
Effector is a powerful and lightweight state management library for JavaScript applications. It provides a simple and predictable way to manage application state, with a focus on type safety and developer experience. Effector is framework-agnostic and can be used with React, Vue, or vanilla JavaScript.
Pros
- Excellent TypeScript support with strong type inference
- Lightweight and performant, with a small bundle size
- Framework-agnostic, can be used with any UI library or vanilla JS
- Clear and predictable data flow with event-driven architecture
Cons
- Steeper learning curve compared to some other state management solutions
- Smaller community and ecosystem compared to Redux or MobX
- Documentation could be more comprehensive, especially for advanced use cases
- Limited middleware support compared to Redux
Code Examples
Creating a store and an event:
import { createStore, createEvent } from 'effector'
const increment = createEvent()
const $counter = createStore(0)
.on(increment, state => state + 1)
$counter.watch(state => console.log('Counter:', state))
increment() // Counter: 1
increment() // Counter: 2
Using Effector with React:
import { createStore, createEvent } from 'effector'
import { useStore } from 'effector-react'
const increment = createEvent()
const $counter = createStore(0).on(increment, state => state + 1)
const Counter = () => {
const count = useStore($counter)
return (
<div>
<p>Count: {count}</p>
<button onClick={() => increment()}>Increment</button>
</div>
)
}
Creating and combining effects:
import { createEffect, combine } from 'effector'
const fetchUserFx = createEffect(async (id) => {
const response = await fetch(`https://api.example.com/users/${id}`)
return response.json()
})
const fetchPostsFx = createEffect(async (userId) => {
const response = await fetch(`https://api.example.com/posts?userId=${userId}`)
return response.json()
})
const $userWithPosts = combine({
user: fetchUserFx.doneData,
posts: fetchPostsFx.doneData,
})
$userWithPosts.watch(console.log)
fetchUserFx(1)
fetchPostsFx(1)
Getting Started
To start using Effector in your project, first install it:
npm install effector
For React integration, also install:
npm install effector-react
Then, you can import and use Effector in your JavaScript or TypeScript files:
import { createStore, createEvent } from 'effector'
const increment = createEvent()
const $counter = createStore(0)
.on(increment, state => state + 1)
$counter.watch(state => console.log('Counter:', state))
increment() // Counter: 1
Competitor Comparisons
🐻 Bear necessities for state management in React
Pros of Zustand
- Simpler API with less boilerplate code
- Easier learning curve for developers familiar with React hooks
- Better TypeScript support out of the box
Cons of Zustand
- Less powerful for complex state management scenarios
- Fewer built-in utilities for derived state and side effects
- Limited ecosystem compared to more established state management libraries
Code Comparison
Zustand:
import create from 'zustand'
const useStore = create((set) => ({
count: 0,
increment: () => set((state) => ({ count: state.count + 1 })),
}))
Effector:
import { createStore, createEvent } from 'effector'
const increment = createEvent()
const $count = createStore(0)
.on(increment, (state) => state + 1)
Both Zustand and Effector are state management libraries for React applications, but they have different approaches and trade-offs. Zustand focuses on simplicity and ease of use, making it a good choice for smaller projects or developers new to state management. Effector, on the other hand, offers a more robust and scalable solution for complex state management needs, but with a steeper learning curve.
The official, opinionated, batteries-included toolset for efficient Redux development
Pros of Redux Toolkit
- Widely adopted and well-established in the React ecosystem
- Comprehensive documentation and large community support
- Includes utilities for common Redux use cases, reducing boilerplate
Cons of Redux Toolkit
- Steeper learning curve due to more complex concepts
- Can be overkill for smaller applications
- Requires more boilerplate code compared to Effector
Code Comparison
Redux Toolkit:
const counterSlice = createSlice({
name: 'counter',
initialState: 0,
reducers: {
increment: state => state + 1,
},
});
Effector:
const increment = createEvent();
const $counter = createStore(0)
.on(increment, state => state + 1);
Redux Toolkit uses a more declarative approach with slices, while Effector employs a more functional style with events and stores. Effector's syntax is generally more concise, but Redux Toolkit provides a more structured way of organizing state logic.
Both libraries aim to simplify state management, but they take different approaches. Redux Toolkit builds upon Redux, offering additional utilities and conventions, while Effector provides a lightweight alternative with a focus on performance and simplicity.
The choice between the two depends on project requirements, team familiarity, and personal preference. Redux Toolkit may be better suited for larger applications with complex state management needs, while Effector could be ideal for smaller projects or those seeking a more minimalist approach.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
âï¸ effector
Business logic with ease
Visit effector.dev for docs, guides and examples
Table of Contents
- Introduction
- Installation
- Documentation
- Packages
- Articles
- Community
- Online playground
- DevTools
- More examples in documentation
- Learn more
- Support us
- Contributors
Introduction
Effector implements business logic with ease for Javascript apps (React/React Native/Vue/Svelte/Node.js/Vanilla), allows you to manage data flow in complex applications. Effector provides best TypeScript support out of the box.
Effector follows five basic principles:
- Application stores should be as light as possible - the idea of adding a store for specific needs should not be frightening or damaging to the developer.
- Application stores should be freely combined - data that the application needs can be statically distributed, showing how it will be converted in runtime.
- Autonomy from controversial concepts - no decorators, no need to use classes or proxies - this is not required to control the state of the application and therefore the api library uses only functions and plain js objects
- Predictability and clarity of API - a small number of basic principles are reused in different cases, reducing the user's workload and increasing recognition. For example, if you know how .watch works for events, you already know how .watch works for stores.
- The application is built from simple elements - space and way to take any required business logic out of the view, maximizing the simplicity of the components.
Installation
You can use any package manager
npm add effector
React
To getting started read our article how to write React and Typescript application.
npm add effector effector-react
SolidJS
npm add effector effector-solid
Vue
npm add effector effector-vue
Svelte
Svelte works with effector out of the box, no additional packages needed. See word chain game application written with svelte and effector.
CDN
- https://www.jsdelivr.com/package/npm/effector
- https://cdn.jsdelivr.net/npm/effector/effector.cjs.js
- https://cdn.jsdelivr.net/npm/effector/effector.mjs
- https://cdn.jsdelivr.net/npm/effector-react/effector-react.cjs.js
- https://cdn.jsdelivr.net/npm/effector-vue/effector-vue.cjs.js
Documentation
For additional information, guides and api reference visit our documentation site
Packages
Articles
- Why I choose Effector instead of Redux or MobX
- Effector â State Manager You Should Give a Try
- Effector vs. Vuex. Which storage management is better for VueJS app?
- Powerful and fast state manager
- Testing api calls with effects and stores
- Effector's beginner guide
- The best part of Effector
Community
- official
- awesome-effector a curated list of awesome effector packages, videos and articles
- Telegram (@effector_en)
- Telegram ð·ðº (@effector_ru)
- dev.to
- Discord
- Add a GitHub Topic
effector
to your project's home page
Online playground
You can try effector with online playground
Code sharing, Typescript and react supported out of the box. Playground repository
DevTools
Use effector-logger for printing updates to console, displaying current store values with ui or connecting application to familiar redux devtools
More examples in documentation
Learn more
Support us
- Read more articles on a patreon page
- Donate on OpenCollective
- Be a sponsor on Github Sponsors
Your support allows us to improve the developer experience ð§¡.
Contributors
Top Related Projects
🐻 Bear necessities for state management in React
The official, opinionated, batteries-included toolset for efficient Redux development
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot