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 🙏

© 2025 – Pkg Stats / Ryan Hefner

d3blackbox

v1.2.0

Published

d3blackbox React component

Downloads

147

Readme

d3blackbox

npm package

Take any D3 example you find in the wild and wrap it in a React component. Great for quick experiments and meeting deadlines. 😛

Meet your deadline in 2 minutes

Check out how it works in a live Codesandbox

  1. Install d3blackbox with npm
$ npm install -s d3blackbox
  1. Find a D3 example you like
  2. Copy its code, put it in a function
  3. Wrap function in D3blackbox
import React from "react";
import D3blackbox from "d3blackbox";
import * as d3 from "d3";

const MyDataviz = D3blackbox(function(anchor, props, state) {
    const svg = d3.select(anchor.current);

    // the rest of your D3 code
});

export default MyDataviz;
  1. Render inside an <svg></svg> element
  2. Enjoy your blackbox D3 component

D3blackbox renders an anchor element and delegates control to your render function. You get an anchor ref, the component's props, and state. Do what you want :)

Great for meeting deadlines and playing around with other people's code. Not recommended for large scale use due to performance constraints. Your render function runs on every component update and redraws the entire DOM subtree. React's rendering engine can't help you.

That's why it's called a sandbox.

What if I don't use D3?

That's okay. D3blackbox lets you delegate control to any rendering library you want. As long as you're okay rendering into a <g></g> element.

You can even use this approach to render Vue apps inside your React apps. 🤨

What if I don't want <g>?

That's okay you weirdo. Use the component argument to specify a different component.

render() {
    return <MyDataviz component="div" />
}

HOCs are so September, do you have hooks?

Yes. Hooks are alpha support and all that, but here's how you can use D3 blackbox as a React hook.

import { useD3 } from "d3blackbox";

function renderSomeD3(anchor) {
    d3.select(anchor);

    // ...
}

const MyD3Component = ({ x, y }) => {
    const refAnchor = useD3(anchor => renderSomeD3(anchor));

    return <g ref={refAnchor} transform={`translate(${x}, ${y})`} />;
};

With love ❤️

Built with love by Swizec Cheers

Only took me 2 years to get around to opensourcing this 😅