Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.04 KB

README.md

File metadata and controls

40 lines (31 loc) · 1.04 KB

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