# react-fiber-traverse

> Traverse and other utils on top of React fiber tree

Latest version **0.0.8** (published 2019-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-fiber-traverse
pnpm add react-fiber-traverse
yarn add react-fiber-traverse
bun add react-fiber-traverse
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2019-09-21 |
| First published | 2019-08-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 293 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | bendtherules |
| Maintainers | bendtherules |
| Keywords | javascript, react, typescript |

## Links

- npm: https://www.npmjs.com/package/react-fiber-traverse
- Repository: https://github.com/bendtherules/react-fiber-traverse
- Homepage: github:bendtherules/react-fiber-traverse
- Issues: github:bendtherules/react-fiber-traverse/issues
- npm.io page: https://npm.io/package/react-fiber-traverse

## Dependencies (3)

- [css-what](https://npm.io/package/css-what.md) ^3.2.0
- [prop-types](https://npm.io/package/prop-types.md) ^15.7.2
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.5.4

## 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.8 (latest) — 2019-09-21
- 0.0.7 — 2019-09-04
- 0.0.6 — 2019-08-29
- 0.0.5 — 2019-08-29
- 0.0.4 — 2019-08-08
- 0.0.3 — 2019-08-08
- 0.0.1 — 2019-08-08

## README

# react-fiber-traverse

[![npm version][npmv-image]][npmv-url]
[![build status][travis-image]][travis-url]
[![coverage status][codecov-image]][codecov-url]
[![npm downloads][npmd-image]][npmd-url]

> Traverse and other utils on top of React fiber tree

## Basic Usage

```ts
import React from "react";
import { render } from "react-dom";

import { findNodeByComponentName, Utils } from "react-fiber-traverse";

// Sample component
// Say, if SomeComponentName looks like this -
function SomeComponentName() {
  return <div>Some text</div>;
}

// Render component
const rootElement = document.getElementById("root");
render(<SomeComponentName />, rootElement);

// Get root node
const rootFiberNode = Utils.getRootFiberNodeFromDOM(rootElement);

// Get component node
const someFiberNode = findNodeByComponentName(
  rootFiberNode,
  "SomeComponentName"
); // <- returns FiberNode for first usage of 'SomeComponentName'

console.log(someFiberNode.child.stateNode); // <- returns reference to the div
console.log(someFiberNode.child.stateNode.innerText); // <- returns 'Some text'

```

## Live Examples

- [Basic Usage](https://codesandbox.io/s/react-example-x82zk?expanddevtools=1&fontsize=14)
<!-- 
## API

**Props**

- `foo` - Something something.
- `bar` - _Optional_ Something something. Defaults to `null`.

**Example**

```jsx
``` -->

## Installation

```
$ npm install react-fiber-traverse --save
```

There are also UMD builds available via [unpkg](https://unpkg.com/):

- https://unpkg.com/react-fiber-traverse/dist/react-fiber-traverse.umd.development.js
- https://unpkg.com/react-fiber-traverse/dist/react-fiber-traverse.umd.production.js

For the non-minified development version, make sure you have already included:

- [`React`](https://unpkg.com/react/umd/react.development.js)
- [`ReactDOM`](https://unpkg.com/react-dom/umd/react-dom.development.js)

For the minified production version, make sure you have already included:

- [`React`](https://unpkg.com/react/umd/react.production.min.js)
- [`ReactDOM`](https://unpkg.com/react-dom/umd/react-dom.production.min.js)

## Overview

This package contains few utility functions which operate over react-fiber tree.

Overall characteristics are:
1. Only read-only operations
2. Support inversion of control

There are few categories of helpers, each with their variations:
1. Find node(s)
2. Traverse node
3. Others - Check node type, find root node, etc.

Little more info is present in docs section.

## Concerns and improvements

Currently, it assumes that nodes are created by `react 16.3+` with appropriate `react-dom`.

Because fiber nodes are internal to react and are supported by multiple renderers, this is an incorrect assumption to make. It should:
1. support diff versions of react (which have fiber node, but slight variations of it)
2. be renderer-agnostic (say, support react-fs-renderer) but with extra helpers for react-dom.
3. heavily tested with all these variations (to know when internals have changed).

## Docs

Docs are sparse at the moment. I plan on adding them soon.

Till then, the auto-generated (typedoc) docs available in [docs folder](./docs/globals.md) might be of some help.



## License

MIT

[travis-image]: https://img.shields.io/travis/bendtherules/react-fiber-traverse/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/bendtherules/react-fiber-traverse
[codecov-image]: https://img.shields.io/codecov/c/github/bendtherules/react-fiber-traverse.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/bendtherules/react-fiber-traverse
[npmv-image]: https://img.shields.io/npm/v/react-fiber-traverse.svg?style=flat-square
[npmv-url]: https://www.npmjs.com/package/react-fiber-traverse
[npmd-image]: https://img.shields.io/npm/dm/react-fiber-traverse.svg?style=flat-square
[npmd-url]: https://www.npmjs.com/package/react-fiber-traverse

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