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

@bndl-io/context-providers-provider

v1.1.0

Published

A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable context usage patterns.

Downloads

216

Readme

@bndl-io/context-providers-provider

A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable patterns for context usage.

Why?

React applications often rely on multiple context providers to manage state, theming, authentication, and more. However, managing these providers can quickly lead to deeply nested and unmanageable component trees, especially when providers depend on one another.

Common Problems:

  1. Context Hell: Wrapping components in multiple layers of context providers makes the tree hard to read and maintain.
  2. Dependency Issues: Incorrect nesting of providers can lead to runtime errors or unexpected behavior.
  3. Encapsulation: Logic for initializing context values often leaks outside of dedicated components, making the code harder to reuse or test.

How @bndl-io/context-providers-provider Solves This:

  • Automatically sorts providers based on their dependencies.
  • Detects circular dependencies and throws helpful error messages.
  • Encourages encapsulation by requiring all context logic to reside in dedicated ProviderComponents.
  • Simplifies application structure by managing provider nesting for you.

Installation

Install the library via npm:

npm install @bndl-io/context-providers-provider

or with yarn:

yarn add @bndl-io/context-providers-provider

Usage

Define Your Providers

Each provider is defined as an object with the following structure:

type ProviderConfig = {
  name: string;
  C: (children: ReactNode) => JSX.Element; // The provider component
  dependencies: string[]; // Names of other providers this provider depends on
};

For example:

const providers = [
  {
    name: 'Auth',
    C: children => <AuthProvider>{children}</AuthProvider>,
    dependencies: ['Theme'], // Auth depends on Theme
  },
  {
    name: 'Theme',
    C: children => <ThemeProvider>{children}</ThemeProvider>,
    dependencies: [], // No dependencies
  },
  {
    name: 'Config',
    C: children => <ConfigProvider>{children}</ConfigProvider>,
    dependencies: ['Auth'], // Config depends on Auth
  },
];

Wrap Your Application

Use the ContextProvidersProvider to automatically sort and nest providers based on their dependencies:

import React from 'react';
import ContextProvidersProvider from '@bndl-io/context-providers-provider';

const providers = [
  {
    name: 'Auth',
    C: children => <AuthProvider>{children}</AuthProvider>,
    dependencies: ['Theme'],
  },
  {
    name: 'Theme',
    C: children => <ThemeProvider>{children}</ThemeProvider>,
    dependencies: [],
  },
  {
    name: 'Config',
    C: children => <ConfigProvider>{children}</ConfigProvider>,
    dependencies: ['Auth'],
  },
];

const App = () => {
  return (
    <ContextProvidersProvider providers={providers}>
      <YourApp />
    </ContextProvidersProvider>
  );
};

Example Output

The above setup would result in the following provider tree:

<ThemeProvider>
  <AuthProvider>
    <ConfigProvider>
      <YourApp />
    </ConfigProvider>
  </AuthProvider>
</ThemeProvider>

API

ContextProvidersProvider

Props:

  • providers: An array of ProviderConfig objects. Each config must include:
    • name: A unique string identifying the provider.
    • C: A function that renders the provider component, wrapping its children.
    • dependencies: An array of strings identifying the providers this provider depends on.
  • children: The children to be rendered inside the nested providers.

Errors:

  • Throws an error if a provider has dependencies that don’t exist.
  • Throws an error if circular dependencies are detected.

createContextProvidersProvider

A utility function to create a ContextProvidersProvider component dynamically.

Usage:

import { createContextProvidersProvider } from '@bndl-io/context-providers-provider';

const providers = [
  {
    name: 'Auth',
    C: children => <AuthProvider>{children}</AuthProvider>,
    dependencies: ['Theme'],
  },
  {
    name: 'Theme',
    C: children => <ThemeProvider>{children}</ThemeProvider>,
    dependencies: [],
  },
  {
    name: 'Config',
    C: children => <ConfigProvider>{children}</ConfigProvider>,
    dependencies: ['Auth'],
  },
];

const ContextWrapper = createContextProvidersProvider({ providers });

const App = () => (
  <ContextWrapper>
    <YourApp />
  </ContextWrapper>
);

export default App;

Description:

  • Dynamically creates a ContextProvidersProvider wrapper with the given providers.
  • Simplifies reusability by abstracting the setup of the ContextProvidersProvider.

License

MIT License

Copyright (c) DatHuis B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Contributing

We welcome contributions! Please open an issue or submit a pull request for any bugs, features, or enhancements.