{"name":"its-fine","version":"2.1.1","keywords":["react","fiber","internal","reconciler","hooks"],"author":{"url":"https://github.com/codyjasonbennett","name":"Cody Bennett"},"license":"MIT","_id":"its-fine@2.1.1","maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"},{"name":"codyjasonbennett","email":"hi@codyb.co"},{"name":"krispyaa","email":"kjbaumgartner@gmail.com"}],"homepage":"https://github.com/pmndrs/its-fine","bugs":{"url":"https://github.com/pmndrs/its-fine/issues"},"dist":{"shasum":"e61e716ac9061e83ff63f8e052373daed2d5e8b6","tarball":"http://registry-npm.ywwl.com/its-fine/download/its-fine-2.1.1.tgz","fileCount":8,"integrity":"sha512-C5ZoVkeqSt0Aje0tzESO+iT/EQpNFNL39GkP7mCACtoZUFD6GcyerFCr6kp0ZtiII4W9HoYkY48Soy5xE/uHKw==","signatures":[{"sig":"MEQCIHXlBdTWWuaou5NMvZLH5n5MeJ7IXLIXon0RG1wESMqmAiBXplvSIhoOuY7tNANjhqdk4/x+AlS1FKNr6yOgsNPTIg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDj73p6q63mmkTJWG1qG9BHVlMLoldzOjA7MoxBTJPWpQIgBfOfY6usdzJ+mlJe0KHldsqNdEqS40w2JGEVLF94NsM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":60079,"size":14357,"noattachment":false,"key":"/its-fine/-/its-fine-2.1.1.tgz"},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","gitHead":"89201ca28eda53e1718346b65313e9fe4f5904b9","scripts":{"test":"vitest run","build":"rimraf dist && vite build && tsc","test:bundle":"node scripts/check-bundle.mjs"},"_npmUser":{"name":"krispyaa","email":"kjbaumgartner@gmail.com"},"repository":{"url":"git+https://github.com/pmndrs/its-fine.git","type":"git"},"_npmVersion":"11.9.0","description":"A collection of escape hatches for React.","directories":{},"sideEffects":false,"_nodeVersion":"24.14.0","dependencies":{"@types/react-reconciler":"^0.28.9"},"react-native":"./dist/index.js","_hasShrinkwrap":false,"devDependencies":{"vite":"^6.1.0","jsdom":"26.1.0","react":"19.2.0","rimraf":"^6.0.1","vitest":"^3.0.6","react-dom":"19.2.0","react-nil":"^2.0.0","typescript":"^5.7.3","@types/node":"^22.13.4","@types/react":"19.2.0","@rsbuild/core":"2.2.9","@types/react-dom":"19.2.0","react-test-renderer":"19.2.0","@types/react-test-renderer":"^19.0.0"},"peerDependencies":{"react":"^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/its-fine_2.1.1_1790285631873_0.748025185301779","host":"s3://npm-registry-packages-npm-production"},"readme":"# its-fine\n\n[![Size](https://img.shields.io/bundlephobia/minzip/its-fine?label=gzip&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/package/its-fine)\n[![Version](https://img.shields.io/npm/v/its-fine?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/its-fine)\n[![Downloads](https://img.shields.io/npm/dt/its-fine.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/its-fine)\n[![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)\n[![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/poimandres)\n\n<p align=\"left\">\n  <a id=\"cover\" href=\"#cover\">\n    <img src=\".github/itsfine.jpg\" alt=\"It's gonna be alright\" />\n  </a>\n</p>\n\nA collection of escape hatches for React.\n\nAs such, you can go beyond React's component abstraction; components are self-aware and can tap into the [React Fiber](https://youtu.be/ZCuYPiUIONs) tree. This enables powerful abstractions that can modify or extend React behavior without explicitly taking reconciliation into your own hands.\n\n## Table of Contents\n\n- [Components](#components)\n  - [FiberProvider](#fiberprovider)\n- [Hooks](#hooks)\n  - [useFiber](#useFiber)\n  - [useContainer](#useContainer)\n  - [useNearestChild](#useNearestChild)\n  - [useNearestParent](#useNearestParent)\n  - [useContextMap](#useContextMap)\n  - [useContextBridge](#useContextBridge)\n  - [useActivityBridge](#useActivityBridge)\n- [Utils](#utils)\n  - [traverseFiber](#traverseFiber)\n\n## Components\n\n### FiberProvider\n\nA react-internal `Fiber` provider. This component binds React children to the React Fiber tree. Call its-fine hooks within this.\n\n> **Note**: pmndrs renderers like react-three-fiber implement this internally to make use of [`useContextBridge`](#usecontextbridge), so you would only need this when using hooks inside of `react-dom` or `react-native`.\n\n```tsx\nimport * as ReactDOM from 'react-dom/client'\nimport { FiberProvider, useFiber } from 'its-fine'\n\nfunction App() {\n  const fiber = useFiber()\n}\n\nReactDOM.createRoot(document.getElementById('root')!).render(\n  <FiberProvider>\n    <App />\n  </FiberProvider>,\n)\n```\n\n## Hooks\n\nUseful React hook abstractions for manipulating and querying from a component. These must be called within a [`FiberProvider`](#fiberprovider) component.\n\n### useFiber\n\nReturns the current react-internal `Fiber`. This is an implementation detail of [react-reconciler](https://github.com/facebook/react/tree/main/packages/react-reconciler).\n\n```tsx\nimport * as React from 'react'\nimport { type Fiber, useFiber } from 'its-fine'\n\nfunction Component() {\n  // Returns the current component's react-internal Fiber\n  const fiber: Fiber<null> | undefined = useFiber()\n\n  // function Component() {}\n  if (fiber) console.log(fiber.type)\n}\n```\n\n### useContainer\n\nReturns the current react-reconciler container info passed to `Reconciler.createContainer`.\n\nIn react-dom, a container will point to the root DOM element; in react-three-fiber, it will point to the root Zustand store.\n\n```tsx\nimport * as React from 'react'\nimport { useContainer } from 'its-fine'\n\nfunction Component() {\n  // Returns the current renderer's root container\n  const container: HTMLDivElement | undefined = useContainer<HTMLDivElement>()\n\n  // <div> (e.g. react-dom)\n  if (container) console.log(container)\n}\n```\n\n### useNearestChild\n\nReturns the nearest react-reconciler child instance or the node created from `Reconciler.createInstance`.\n\nIn react-dom, this would be a DOM element; in react-three-fiber this would be an `Instance` descriptor.\n\n```tsx\nimport * as React from 'react'\nimport { useNearestChild } from 'its-fine'\n\nfunction Component() {\n  // Returns a React Ref which points to the nearest child <div /> element.\n  // Omit the element type to match the nearest element of any kind\n  const childRef: React.MutableRefObject<HTMLDivElement | undefined> = useNearestChild<HTMLDivElement>('div')\n\n  // Access child Ref on mount\n  React.useEffect(() => {\n    // <div> (e.g. react-dom)\n    const child = childRef.current\n    if (child) console.log(child)\n  }, [])\n\n  // A child element, can live deep down another component\n  return <div />\n}\n```\n\n### useNearestParent\n\nReturns the nearest react-reconciler parent instance or the node created from `Reconciler.createInstance`.\n\nIn react-dom, this would be a DOM element; in react-three-fiber this would be an instance descriptor.\n\n```tsx\nimport * as React from 'react'\nimport { useNearestParent } from 'its-fine'\n\nfunction Component() {\n  // Returns a React Ref which points to the nearest parent <div /> element.\n  // Omit the element type to match the nearest element of any kind\n  const parentRef: React.MutableRefObject<HTMLDivElement | undefined> = useNearestParent<HTMLDivElement>('div')\n\n  // Access parent Ref on mount\n  React.useEffect(() => {\n    // <div> (e.g. react-dom)\n    const parent = parentRef.current\n    if (parent) console.log(parent)\n  }, [])\n}\n\n// A parent element wrapping Component, can live deep up another component\n;<div>\n  <Component />\n</div>\n```\n\n### useContextMap\n\nReturns a map of all contexts and their values.\n\n```tsx\nimport * as React from 'react'\nimport { useContextMap } from 'its-fine'\n\nconst SomeContext = React.createContext<string>(null!)\n\nfunction Component() {\n  const contextMap = useContextMap()\n  return contextMap.get(SomeContext)\n}\n```\n\n### useContextBridge\n\nReact Context currently cannot be shared across [React renderers](https://reactjs.org/docs/codebase-overview.html#renderers) but explicitly forwarded between providers (see [react#17275](https://github.com/facebook/react/issues/17275)). This hook returns a `ContextBridge` of live context providers to pierce Context across renderers.\n\nPass `ContextBridge` as a component to a secondary renderer to enable context-sharing within its children.\n\n```tsx\nimport * as React from 'react'\n// react-nil is a secondary renderer that is usually used for testing.\n// This also includes Fabric, react-three-fiber, etc\nimport * as ReactNil from 'react-nil'\n// react-dom is a primary renderer that works on top of a secondary renderer.\n// This also includes react-native, react-pixi, etc.\nimport * as ReactDOM from 'react-dom/client'\nimport { type ContextBridge, useContextBridge, FiberProvider } from 'its-fine'\n\nfunction Canvas(props: { children: React.ReactNode }) {\n  // Returns a bridged context provider that forwards context\n  const Bridge: ContextBridge = useContextBridge()\n  // Renders children with bridged context into a secondary renderer\n  ReactNil.render(<Bridge>{props.children}</Bridge>)\n}\n\n// A React Context whose provider lives in react-dom\nconst DOMContext = React.createContext<string>(null!)\n\n// A component that reads from DOMContext\nfunction Component() {\n  // \"Hello from react-dom\"\n  console.log(React.useContext(DOMContext))\n}\n\n// Renders into a primary renderer like react-dom or react-native,\n// DOMContext wraps Canvas and is bridged into Component\nReactDOM.createRoot(document.getElementById('root')!).render(\n  <FiberProvider>\n    <DOMContext.Provider value=\"Hello from react-dom\">\n      <Canvas>\n        <Component />\n      </Canvas>\n    </DOMContext.Provider>\n  </FiberProvider>,\n)\n```\n\n### useActivityBridge\n\nReturns a stable `ActivityBridge` that forwards ancestor `<Activity>` visibility into another React root while preserving child state. Requires React 19.2+ and an Activity capable renderer.\n\n```tsx\nimport * as React from 'react'\nimport * as ReactDOM from 'react-dom/client'\nimport { useActivityBridge, FiberProvider } from 'its-fine'\n\n// The application owns the destination root and its cleanup\nconst destination = ReactDOM.createRoot(document.getElementById('destination')!)\n\nfunction Canvas(props: { children: React.ReactNode }) {\n  // Forwards Activity visibility. Use useContextBridge separately for context\n  const Bridge = useActivityBridge()\n  // Render after the source commits. Removing Canvas hides the destination\n  React.useLayoutEffect(() => {\n    destination.render(<Bridge>{props.children}</Bridge>)\n  })\n  return null\n}\n\nReactDOM.createRoot(document.getElementById('source')!).render(\n  <FiberProvider>\n    {/* Set mode to \"hidden\" to hide both roots' children while preserving state */}\n    <React.Activity mode=\"visible\">\n      <Canvas>\n        <div>Scene</div>\n      </Canvas>\n    </React.Activity>\n  </FiberProvider>,\n)\n```\n\nIf the source shows a Suspense loading fallback, the destination stays visible unless an ancestor Activity is hidden.\n\n## Utils\n\nAdditional exported utility functions for raw handling of Fibers.\n\n### traverseFiber\n\nTraverses up or down a `Fiber`, return `true` to stop and select a node.\n\n```ts\nimport { type Fiber, traverseFiber } from 'its-fine'\n\n// Traverses through the Fiber tree, returns the current node when `true` is passed via selector\nconst parentDiv: Fiber<HTMLDivElement> | undefined = traverseFiber<HTMLDivElement>(\n  // Input Fiber to traverse\n  fiber as Fiber,\n  // Whether to ascend and walk up the tree. Will walk down if `false`\n  true,\n  // A Fiber node selector, returns the first match when `true` is passed\n  (node: Fiber<HTMLDivElement | null>) => node.type === 'div',\n)\n```\n","publish_time":1790285631976,"_cnpm_publish_time":1790285631976,"dist-tags":{"latest":"2.1.1"}}