{"id":13401082,"url":"https://github.com/pmndrs/react-nil","last_synced_at":"2025-05-14T16:01:45.093Z","repository":{"id":49149677,"uuid":"295834617","full_name":"pmndrs/react-nil","owner":"pmndrs","description":"⃝ A react null renderer","archived":false,"fork":false,"pushed_at":"2024-05-15T19:31:20.000Z","size":341,"stargazers_count":795,"open_issues_count":2,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-29T15:32:10.518Z","etag":null,"topics":["fiber","node","null","react","renderer"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmndrs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-15T19:53:38.000Z","updated_at":"2024-10-24T11:59:39.000Z","dependencies_parsed_at":"2024-04-12T18:23:14.120Z","dependency_job_id":"67672bb6-8d64-4728-8369-bd315b117db5","html_url":"https://github.com/pmndrs/react-nil","commit_stats":{"total_commits":51,"total_committers":5,"mean_commits":10.2,"dds":0.3529411764705882,"last_synced_commit":"667cf882a67390e87978a53922e4b03a3da79e4d"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmndrs%2Freact-nil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmndrs%2Freact-nil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmndrs%2Freact-nil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmndrs%2Freact-nil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmndrs","download_url":"https://codeload.github.com/pmndrs/react-nil/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247750811,"owners_count":20989839,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fiber","node","null","react","renderer"],"created_at":"2024-07-30T19:00:58.502Z","updated_at":"2025-04-08T12:09:11.736Z","avatar_url":"https://github.com/pmndrs.png","language":"TypeScript","readme":"[![Size](https://img.shields.io/bundlephobia/minzip/react-nil?label=gzip\u0026style=flat\u0026colorA=000000\u0026colorB=000000)](https://bundlephobia.com/package/react-nil)\n[![Version](https://img.shields.io/npm/v/react-nil?style=flat\u0026colorA=000000\u0026colorB=000000)](https://npmjs.com/package/react-nil)\n[![Downloads](https://img.shields.io/npm/dt/react-nil.svg?style=flat\u0026colorA=000000\u0026colorB=000000)](https://npmjs.com/package/react-nil)\n[![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs\u0026style=flat\u0026colorA=000000\u0026colorB=000000\u0026logo=twitter\u0026logoColor=000000)](https://twitter.com/pmndrs)\n[![Discord](https://img.shields.io/discord/740090768164651008?style=flat\u0026colorA=000000\u0026colorB=000000\u0026label=discord\u0026logo=discord\u0026logoColor=000000)](https://discord.gg/poimandres)\n\n\u003cp align=\"left\"\u003e\n  \u003ca id=\"cover\" href=\"#cover\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\".github/dark.svg\"\u003e\n      \u003cimg style=\"white-space:pre-wrap\" alt=\"There are legitimate use cases for null components or logical components.\u0026#10\u0026#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\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n#### Nothing to see here ...\n\nQuite 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.\n\nYou can try a small demo here: https://codesandbox.io/s/react-nil-mvpry\n\n#### How does it work?\n\nThe following renders a logical component without a view, it renders nothing, but it has a real lifecycle and is managed by React regardless.\n\n```jsx\nimport { useState, useEffect } from 'react'\nimport { render } from 'react-nil'\n\nfunction Foo() {\n  const [active, set] = useState(false)\n  useEffect(() =\u003e void setInterval(() =\u003e set((a) =\u003e !a), 1000), [])\n\n  // false, true, ...\n  console.log(active)\n}\n\nrender(\u003cFoo /\u003e)\n```\n\nWe can take this further by rendering made-up elements that get returned as a reactive JSON tree from `render`.\n\nYou can take a snapshot for testing via `React.act` which will wait for effects and suspense to finish.\n\n```tsx\nimport { useState, useEffect, act } from 'react'\nimport { render } from 'react-nil'\n\ndeclare module 'react' {\n  namespace JSX {\n    interface IntrinsicElements {\n      timestamp: Record\u003cstring, unknown\u003e\n    }\n  }\n}\n\nfunction Test() {\n  const [value, setValue] = useState(-1)\n  useEffect(() =\u003e setValue(Date.now()), [])\n  return \u003ctimestamp value={value} /\u003e\n}\n\nconst container = await act(async () =\u003e render(\u003cTest /\u003e))\n\n// { type: 'timestamp', props: { value: number }, children: [] }\nconsole.log(container.head)\n```\n","funding_links":[],"categories":["Uncategorized","TypeScript","JavaScript","React [🔝](#readme)"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmndrs%2Freact-nil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmndrs%2Freact-nil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmndrs%2Freact-nil/lists"}