Build modular
React apps.
Put state and behavior in injectable modules. Connect them to React views or sync them across browser tabs with Reactant Share.
pnpm dlx reactant-cli init my-app@injectable({ name: 'counter' })
class Counter {
@state count = 0;
@action
add(step: number) {
this.count += step;
}
}Loading the live example…
Inside a Reactant app
An application layer for React
Modules hold state and behavior, dependency injection wires them together, and views stay small enough to read at a glance.
Compose modules with dependency injection
Declare what a module needs in its constructor. Reactant builds the graph, and tests can replace any piece of it.
Mutable syntax, immutable state
Update state with plain assignments inside an @action. Redux and Mutative turn them into immutable updates.
Views render what they read
useConnector subscribes a view to the values it selects, so unrelated changes leave it alone.
Share across tabs and workers
Run one app instance in a SharedWorker or a tab, and keep every window in sync with Reactant Share.
Plug in what you need
Routing, persistence, and Redux middleware arrive as plugin modules that use the same injection.
Test any module in isolation
testBed creates the app without rendering, and lets you provide a stand-in for any dependency.
One model, every platform
Render the same modules on the web, in React Native, or on the server.
Architecture
Every layer has one job
Views stay thin, services own the logic, and one store applies every change. Each layer depends only on the layers below it.
- 01View
component()A React component reads state with useConnector and calls module methods. - 02ViewModule
extends ViewModuleDeclares the services a screen needs and pairs them with its component. - 03Services
@injectable()Plain classes own @state and @action and receive their dependencies. - 04Store and plugins
createApp()Builds the Redux store, applies each action immutably, and lets plugins add middleware and context.
Actions travel downState flows back up
Reactant Share
One app, every tab
Reactant Share runs your app once, in a SharedWorker or a host tab, and renders it in every window. Clients send actions to that one instance, and each change reaches all of them together.
Ecosystem
Pick the pieces you need
The core runs on its own. Add a renderer for your platform, then plugins for routing, persistence, and sharing. All 15 packages ship together, currently at v0.150.0.
Core
5reactantcreateApp, testBed, decorators, and hooks in one import.reactant-moduleThe module model behind ViewModule, PluginModule, and the store.reactant-diThe dependency injection container and decorators.reactant-modelDefine state and actions as a plain object model.reactant-reduxUse classic Redux reducers and actions as a module.
Renderers
3Plugins
4Share and tooling
3Get started
Build your next app with Reactant
Create a Vite project with the CLI, in TypeScript by default, or add Reactant to an existing React 18 app.
pnpm dlx reactant-cli init my-app
cd my-app
pnpm start