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

use-children

v0.1.0

Published

Filter React children for specific component

Readme

use-children

Filter React children for specific component

Install

NPM:

npm install --save use-children

Yarn:

yarn add use-children

Usage

Read the Why? section for a more detailed explanation.

import useChildren from "useChildren";

const ModalContent = () => {
  return <>{/** Some JSX */}</>;
};

const ModalOverlay = () => {
  return <>{/** Some JSX */}</>;
};

const ModalRoot = ({ children, isOpen }) => {
  // withOverlay is an array of all ModalOverlay components
  const [withOverlay] = useChildren(children, ModalOverlay);
  // withContent is an array of all MdalContent components
  const [withContent] = useChildren(children, ModalContent);

  return (
    <div className="modal-root">
      {isOpen ? (
        <>
          {withOverlay}
          {withContent}
        </>
      ) : null}
    </div>
  );
};

Why?

Imagine you're building a Modal component which consists of three components:

  1. ModalRoot - Portal component
  2. ModalOverlay - Overlay component
  3. ModalContent - The primary content container component

where the intended usage is the following:

import { useState } from "react";
import { ModalRoot, ModalOverlay, ModalContent } from "../modal";

const MyModal = () => {
  const [open, setOpen] = useState(false);

  const openModal = () => setOpen(true);
  const closeModal = () => setOpen(false);

  return (
    <ModalRoot isOpen={open}>
      <ModalOverlay />
      <ModalContent />
    </ModalRoot>
  );
};

However, since ModalRoot does not force the user to pass in only ModalOverlay and ModalContent. The user can also do the following:

import { useState } from "react";
import { ModalRoot, ModalOverlay, ModalContent } from "../modal";

const MyModal = () => {
  const [open, setOpen] = useState(false);

  const openModal = () => setOpen(true);
  const closeModal = () => setOpen(false);

  return (
    <ModalRoot isOpen={open}>
      <div>Some content</div>
    </ModalRoot>
  );
};

With use-children you can filter for just ModalContent and ModalOverlay

Credits