# @de-pa/react

> React with dependency injection. A fork of React that adds constructor-based DI.

Latest version **0.0.7** (published 2026-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @de-pa/react
pnpm add @de-pa/react
yarn add @de-pa/react
bun add @de-pa/react
```

## Health

**Score 55/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2026-07-19 |
| First published | 2021-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=0.10.0 |
| Dependencies | 3 |
| Unpacked size | 393.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | wl843022618 |
| Keywords | react, dependency-injection |

## Links

- npm: https://www.npmjs.com/package/@de-pa/react
- Repository: https://github.com/John-Oldman-Wang/de-pa-react
- Issues: https://github.com/John-Oldman-Wang/de-pa-react/issues
- npm.io page: https://npm.io/package/@de-pa/react

## Dependencies (3)

- [csstype](https://npm.io/package/csstype.md) ^3.0.2
- [loose-envify](https://npm.io/package/loose-envify.md) ^1.1.0
- [@types/prop-types](https://npm.io/package/@types/prop-types.md) *

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.7 (latest) — 2026-07-19
- 0.0.2-beta1 (beta) — 2021-05-25
- 0.0.6 — 2021-06-03
- 0.0.5 — 2021-06-01
- 0.0.4 — 2021-06-01
- 0.0.3 — 2021-06-01
- 0.0.2 — 2021-05-05
- 0.0.1 — 2021-05-04
- 0.0.1-beta2 — 2021-05-04
- 0.0.1-beta1 — 2021-05-04

## README

# `@de-pa/react`

`@de-pa/react` is a fork of [React](https://react.dev/) that adds a
**constructor-based dependency injection** pattern (powered by
[injection-js](https://github.com/mgechev/injection-js)). The public React API
is unchanged — you can use it exactly like `react`, and opt into DI where you
want it.

It is used together with the matching renderer, `@de-pa/react-dom`.

## Installation

```
npm i @de-pa/react @de-pa/react-dom injection-js reflect-metadata --save
```

Dependency injection requires **TypeScript** with `experimentalDecorators` and
`emitDecoratorMetadata` enabled, and `reflect-metadata` imported **once** at your
entry point. Ordinary (non-DI) components need none of this and behave exactly
like stock React.

> The bundled type definitions are derived from `@types/react@18.3` and require
> **TypeScript ≥ 5.1**. Do **not** also install `@types/react` — this package
> ships its own types (they would otherwise conflict).

`tsconfig.json`:

```json
{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "jsx": "react"
  }
}
```

## Usage

```tsx
import 'reflect-metadata';
import { Component, IComponent, InjectionProvider } from '@de-pa/react';
import { render } from '@de-pa/react-dom';

class Service {
  method() {
    return 'hello world';
  }
}

@IComponent()
class App extends Component {
  constructor(public service: Service) {
    super();
  }
  render() {
    return <div>{this.service.method()}</div>;
  }
}

render(
  <InjectionProvider providers={[Service]}>
    <App />
  </InjectionProvider>,
  document.body,
);
```

### A component can provide its own services

`@IComponent({ providers: [...] })` lets a class declare its own providers. Such
a service is created **once per class per enclosing `<InjectionProvider>`** (a
scoped singleton), layered on top of the `<InjectionProvider>`'s services:

```tsx
@IComponent({ providers: [LocalService] })
class Panel extends Component {
  constructor(public local: LocalService) {
    super();
  }
  render() {
    return <div>{this.local.value()}</div>;
  }
}
```

## Versioning & React base

`@de-pa/react` uses its **own** semantic version. The upstream React version it
is built on is reported at runtime as `React.version` (and listed below).
`@de-pa/react` and `@de-pa/react-dom` are always released together at the same
version.

| `@de-pa/react` | React base (`React.version`) | Notes |
| -------------- | ---------------------------- | ----- |
| `0.0.7`        | `18.3.1`                     | rebased onto React 18; per-class injector + `@IComponent({ providers })`; drop-in `require('@de-pa/react')` |
| `0.0.6`        | `17.x`                       | initial line (React 17 base) |

While on `0.x` the API is still evolving. A `1.0.0` will be cut once the DI API
is stable.

## License

`@de-pa/react` is [MIT licensed](./LICENSE).

---
_Source: https://npm.io/package/@de-pa/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
