npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-fiber-traverse

v0.0.8

Published

Traverse and other utils on top of React fiber tree

Downloads

142

Readme

react-fiber-traverse

npm version build status coverage status npm downloads

Traverse and other utils on top of React fiber tree

Basic Usage

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

Installation

$ npm install react-fiber-traverse --save

There are also UMD builds available via unpkg:

  • 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:

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

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 might be of some help.

License

MIT