@saneksa/react-context-composer
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

NPM GitHub license

Installation

yarn add @saneksa/react-context-composer

The Problem

In projects on react there are a lot of contexts, it becomes very difficult to read such things

<ContextA.Provider>
  <ContextB.Provider>
    <ContextC.Provider>...</ContextC.Provider>
  </ContextB.Provider>
</ContextA.Provider>

Usage

See it in action at codesandbox

function App() {
  return composeContexts([
    [ThemeContext, theme[Theme.red]],
    [LanguageContext, Languages.cn],
  ])(
    <div>
      <Children />
      <br />
      ...child elements using contexts
    </div>
  );
}

In my proposed variant, the check of context value types works correctly

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.1.02latest

Version History

VersionDownloads (Last 7 Days)Published
2.1.02
2.0.00
1.0.10
1.0.00

Package Sidebar

Install

npm i @saneksa/react-context-composer

Weekly Downloads

2

Version

2.1.0

License

MIT

Unpacked Size

4.42 kB

Total Files

6

Last publish

Collaborators

  • saneksa20