
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
use-children
Advanced tools
Filter React children for specific component
NPM:
npm install --save use-children
Yarn:
yarn add use-children
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>
);
};
Imagine you're building a Modal component which consists of three components:
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
FAQs
Filter React children for specific component
We found that use-children demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.