# react-nil

> A react custom renderer that renders nothing but logical components

Latest version **2.0.0** (published 2025-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-nil
pnpm add react-nil
yarn add react-nil
bun add react-nil
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-01-13 |
| First published | 2020-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 32.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 999 |
| Author | Cody Bennett |
| Maintainers | drcmda, codyjasonbennett |
| Keywords | react, null, nil, renderer, node |

## Links

- npm: https://www.npmjs.com/package/react-nil
- Repository: https://github.com/pmndrs/react-nil
- npm.io page: https://npm.io/package/react-nil

## Dependencies (2)

- [react-reconciler](https://npm.io/package/react-reconciler.md) ^0.31.0
- [@types/react-reconciler](https://npm.io/package/@types/react-reconciler.md) ^0.28.9

## 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

- 2.0.0 (latest) — 2025-01-13
- 1.3.1 — 2025-01-13
- 1.3.0 — 2025-01-13
- 1.2.0 — 2022-09-07
- 1.1.2 — 2022-09-06
- 1.1.1 — 2022-09-05
- 1.1.0 — 2022-09-04
- 1.0.1 — 2022-09-04
- 1.0.0 — 2022-09-04
- 0.0.3 — 2020-09-16
- 0.0.2 — 2020-09-16
- 0.0.1 — 2020-09-15
- 0.0.0 — 2020-09-15

## README

[![Size](https://img.shields.io/bundlephobia/minzip/react-nil?label=gzip&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/package/react-nil)
[![Version](https://img.shields.io/npm/v/react-nil?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/react-nil)
[![Downloads](https://img.shields.io/npm/dt/react-nil.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/react-nil)
[![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)
[![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/poimandres)

<p align="left">
  <a id="cover" href="#cover">
    <picture>
      <source media="(prefers-color-scheme: dark)" srcset=".github/dark.svg">
      <img style="white-space:pre-wrap" alt="There are legitimate use cases for null components or logical components.&#10&#10A component has a lifecycle, local state, packs side-effects into useEffect, memoizes calculations in useMemo, orchestrates async ops with suspense, communicates via context, maintains fast response with concurrency. And of course — the entire React ecosystem is available." src=".github/light.svg">
    </picture>
  </a>
</p>

#### Nothing to see here ...

Quite so. This package allows you to bring React's high-level component abstraction to Node or wherever you need it. Why not manage your REST endpoints like routes on the client, users as components with mount/unmount lifecycles, self-contained separation of concern, and clean side effects? Suspense for requests, etc.

You can try a small demo here: https://codesandbox.io/s/react-nil-mvpry

#### How does it work?

The following renders a logical component without a view, it renders nothing, but it has a real lifecycle and is managed by React regardless.

```jsx
import { useState, useEffect } from 'react'
import { render } from 'react-nil'

function Foo() {
  const [active, set] = useState(false)
  useEffect(() => void setInterval(() => set((a) => !a), 1000), [])

  // false, true, ...
  console.log(active)
}

render(<Foo />)
```

We can take this further by rendering made-up elements that get returned as a reactive JSON tree from `render`.

You can take a snapshot for testing via `React.act` which will wait for effects and suspense to finish.

```tsx
import { useState, useEffect, act } from 'react'
import { render } from 'react-nil'

declare module 'react' {
  namespace JSX {
    interface IntrinsicElements {
      timestamp: Record<string, unknown>
    }
  }
}

function Test() {
  const [value, setValue] = useState(-1)
  useEffect(() => setValue(Date.now()), [])
  return <timestamp value={value} />
}

const container = await act(async () => render(<Test />))

// { type: 'timestamp', props: { value: number }, children: [] }
console.log(container.head)
```

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