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

@astro-utils/context

v1.2.1

Published

React like Context for astro.js

Readme

Astro Utils Context

Share values across your Astro component tree.

npm version MIT license Documentation

Documentation · Examples · AI agent guide

Provide values once in a layout and read them in nested components. Context exists during a render; it is not a browser store or persistent session.

Supports Astro 7 and parallel async rendering. Context now uses Node's AsyncLocalStorage from node:async_hooks instead of a shared render stack. Values follow the async execution started inside their provider, including across await, while overlapping providers and separate requests keep their own context. The Context.astro, getContext, and asyncContext APIs stay the same.

Install

npm install @astro-utils/context

Provide → read → render

src/components/Button.astro

---
import getContext from '@astro-utils/context';
const { buttonColor } = getContext(Astro, 'buttons');
---
<button style={{ color: buttonColor }}>
    </slot>
</button>

src/pages/index.astro

---
import Layout from '../layouts/Layout.astro';
import PageHeading from '../components/PageHeading.astro';
import Context from '@astro-utils/context/Context.astro';

---
<Layout title="Context Demo">
    <h1>Colorful buttons</h1>

    <Context buttonColor="red">
        <Button>Click Red</Button>
        <Button>Red button</Button>
    </Context>

    <Context buttonColor="blue">
        <Button>Click Blue</Button>
        <Button>Blue button</Button>
    </Context>
</Layout>

Parallel async context

Use asyncContext to start work inside a context. Parallel calls inherit their parent's values, and each call can override values without changing its siblings' context:

import getContext, { asyncContext } from '@astro-utils/context';

const [firstTitle, secondTitle] = await Promise.all(
        asyncContext(() => {
            return Astro.slots.default();
        }, Astro, { name: 'task', context: { title: "First Title" } }),

        asyncContext(() => {
            return Astro.slots.default();
        }, Astro, { name: 'task', context: { title: "Second Title" } })
);

Context no longer uses locks: parallel providers keep independent async scopes.

Know the boundaries

  • Nested providers with the same name inherit values and can override them.
  • getContext(Astro, name) returns {} when no provider is active; the default name is "default".
  • asyncContext supports manual async rendering with context.
  • The server runtime must support Node's node:async_hooks and AsyncLocalStorage.

Full walkthrough · API reference

Support Astro Utils

If Astro Utils helps you build, a star on GitHub is appreciated. Bug reports, useful examples, and pull requests help too. Thank you for supporting the project.

MIT license