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 🙏

© 2026 – Pkg Stats / Ryan Hefner

child-locator

v0.12.0

Published

A React Hook for locating child components at specific coordinates within a parent container

Readme

child-locator

A React Hook for detecting child components at specific XY coordinates within a container element.

NPM child-locator Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

What is this?

If you're hesitant to manipulate delicate Observers to retrieve elements at specific positions displayed in the browser using React, the child-locator package might be useful.

This package identifies elements within a specified visible area of the page and makes it easy to retrieve the information held by those elements. Since it's implemented using callback handlers, it can detect changes even when the layout shifts and elements change.

The detection position is not limited to absolute coordinates; it can also use various CSS units, enabling stable position detection for responsive design pages.

demo project

Features:

  • XY Coordinate Detection: Precisely locate child components at specified coordinates
  • CSS Unit Support: Coordinate values support px (number), %, vw, vh, rem, em (string) and other CSS units
  • Real-time Monitoring: Automatically detects changes in child elements using MutationObserver, ResizeObserver, and IntersectionObserver

Installation

npm install child-locator

Basic Usage

1. Setup Provider

First, setup your app with ChildLocatorProvider:

import React from 'react';
import { ChildLocatorProvider } from 'child-locator';
import App from './App';

function Root() {
  return (
    <ChildLocatorProvider>
      <App />
    </ChildLocatorProvider>
  );
}

2. Create Trackable Components

Use withChildLocator to make components trackable:

import React from 'react';
import { withChildLocator } from 'child-locator';

type BaseChildItemProps = {
  id: number;
  children: React.ReactNode;
};

// Base (simple) component.
const BaseChildItem = ({ id, children }: BaseChildItemProps) => {
  return <div data-testid={`child-${id}`}>{children}</div>;
};

// withChildLocator will inject the DOM anchor automatically.
const ChildItem = withChildLocator(BaseChildItem);

When a component does not expose a ref, withChildLocator automatically injects an invisible wrapper so that the element can still be tracked. See the dedicated withChildLocator section below for that pattern.

3. Use Detection Hook

Use useLocator to detect components at specific coordinates:

import React, { useRef } from 'react';
import { useLocator } from 'child-locator';
import type { DetectedComponent } from 'child-locator';

const ParentComponent = () => {
  // Makes refer the container
  const containerRef = useRef<HTMLDivElement>(null);

  useLocator(containerRef, {
    // Detection coordinates: CSS units supported: px, %, vw, vh, rem, em
    offset: { x: '50%', y: '30%' },
    // Detected callback:
    onDetect: (component: DetectedComponent) => {
      if (component.element) {
        console.log('Detected element:', component.element);
        console.log('Distance from target:', component.distanceFromOffset);
        console.log(
          'Component metadata:',
          component.component?.props._tetherMetadata
        );
      } else {
        console.log('No child elements at target coordinates');
      }
    },
    enabled: true,
  });

  // Place detection target items into the container
  return (
    <div
      ref={containerRef}
      style={{ width: 400, height: 300, position: 'relative' }}
    >
      <ChildItem id={1} tetherMetadata={{ type: 'grid-item', row: 1, col: 1 }}>
        Item 1
      </ChildItem>
      <ChildItem id={2} tetherMetadata={{ type: 'grid-item', row: 1, col: 2 }}>
        Item 2
      </ChildItem>
      <ChildItem id={3} tetherMetadata={{ type: 'grid-item', row: 2, col: 1 }}>
        Item 3
      </ChildItem>
    </div>
  );
};

Documentation

See repository douments for detail.

License

Under MIT.