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

react-graft

v1.0.1

Published

A factory that turns a hook into a typed React context, with side effects that belong to the provider.

Readme

react-graft

Turns a hook into a React context: a Provider that mounts it, a use() that reads it, and side effects that belong to the provider instead of to whichever component happened to be mounted.

Over a context written by hand it adds three things: provider props typed from the hook's own signature, a context nobody can supply from outside, and inject.

Package: npmjs.com/package/react-graft

Documentation: dev.robertoattanasio.com/react-graft

Install

npm install react-graft

Usage

Write a hook. What it returns is the value; what it accepts becomes a prop on the provider.

export const GraftLikes = createGraft({
  name: "GraftLikes",
  graft: useGraft,
});

function useGraft({ start = 0 }: { start?: number }) {
  const [value, setValue] = useState(start);
  const like = useCallback(() => setValue((count) => count + 1), []);

  return { value, like };
}
<GraftLikes.Provider start={10}>
  <LikeButton />
</GraftLikes.Provider>;

const { value, like } = GraftLikes.use();

Two providers are two independent instances. use() throws, naming the graft, when it is called outside its provider.

inject

inject takes hooks, not components. Each runs inside the provider, in a component of its own that renders null, and receives the value the graft produced — the same object use() returns.

export const GraftLikes = createGraft({
  name: "GraftLikes",
  graft: useGraft,
  inject: [useInjectTitle],
});

function useInjectTitle({ value }: { value: number }) {
  useEffect(() => {
    document.title = `${value} likes`;
  }, [value]);
}

They are siblings of children, never wrappers, so an injected effect keeps running when the tree below it unmounts — which is what lets a graft be the thing that reopens what it closed.

API

createGraft(options)

| option | type | default | | | -------- | ----------------------------- | --------- | ---------------------------------- | | graft | (options) => TValue | required | the hook the provider mounts | | inject | ((value: TValue) => void)[] | [] | hooks run inside the provider | | name | string | "Graft" | shown in DevTools and in the error |

Returns { Provider, use, displayName }.

Notes

  • The context is private. Mounting the provider is the only way to supply a value.
  • The value is rebuilt on every render, so every reader wakes when the provider does. Grafts are meant to be many and narrow.
  • Injected hooks run after children, in the order of the array.
  • Graft.use() and the entries of inject are hook names, so react-hooks/rules-of-hooks sees them.
  • Nothing here renders, touches the DOM or reaches for a platform API.

Built with

React 19 and TypeScript. No dependencies.

Conventions for contributing: RULE.md.

License

MIT.