effector-react provides the official React bindings for the effector state management library, allowing developers to seamlessly integrate effector's reactive, event-driven state model with their React applications. The current stable version is 23.3.0, frequently updated in parallel with the core effector library. Its key differentiators include a declarative, algebraic effects paradigm for managing complex application logic, which promotes clear separation of concerns between business logic and UI. It offers optimized React hooks, notably useUnit, for consuming effector stores, events, and effects, ensuring efficient component re-renders and simplified access to application state and actions. The library also boasts strong TypeScript support and recently added compatibility for React 19.
npm install effector-reactVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to create an Effector store and event, then consume them in a React functional component using the `useUnit` hook to manage form input state and display its length.
Migrate your project to use ES modules (`import ... from '...'`) and configure your build system (Webpack, Rollup, Vite, etc.) to handle them correctly. Ensure your `package.json` has `"type": "module"` or uses `.mjs` extensions for ESM files.
Install `@effector/babel-plugin` (or the equivalent SWC plugin) and configure it in your project's `babel.config.js` or `swc-config` file. Refer to the official Effector documentation for detailed setup instructions.
Verify your `package.json` for `react` and `effector` and ensure they fall within the specified peer dependency ranges. Use `npm install` or `yarn add` to adjust versions if necessary. `npm ls react effector` can help diagnose issues.
Prefer `useUnit` when consuming effector stores, events, or effects. For example, instead of `const value = useStore($store);`, consider `const { value } = useUnit({ value: $store });`.Ensure `effector-react` hooks are only invoked within the render function of a React functional component or at the top level of another custom hook. Check for conditional hook calls or calls within regular JavaScript functions.
Verify that you are using ES module imports (`import ... from '...'`) throughout your Effector codebase. Ensure the `@effector/babel-plugin` (or SWC equivalent) is correctly installed and configured in your build setup, especially if using HMR or hot reloading. Update to the latest `effector` and `effector-react` versions.
Check your import statement: `import { useUnit } from 'effector-react'`. Confirm `effector-react` is correctly installed. Ensure your build tool (Webpack, Babel, etc.) is configured to handle ES Modules from `node_modules` correctly, especially if you have custom aliases or transformations.