@evanion/compose
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

Known Vulnerabilities npm (scoped)

compose

A React component that allows you to cleanup your providers.

Raise your hand if your App.tsx looks like this

const App: React.FC = () => {
  return (
    <ErrorBoundary>
      <CacheProvider value={emotionCache}>
        <ThemeProvider theme={theme}>
          <TranslationProvider locale={locale} messages={messages}>
            <StateProvider state={stateStore}>
              <CoffeeProvider>
                <SanityProvider>
                  <Routes />
                </SanityProvider>
              </CoffeeProvider>
            </StateProvider>
          </TranslationProvider>
        </ThemeProvider>
      </CacheProvider>
    </ErrorBoundary>
  );
};

This package let's you go to this:

import { Provider, ComposeProvider } from "@evanion/compose";
const providers: Provider[] = [
  ErrorBoundary,
  [CacheProvider, { value: emotionCache }],
  [ThemeProvider, { theme }],
  [TranslationProvider, { locale, messages }],
  [StateProvider, { state: stateStore }],
  CoffeeProvider,
  SanityProvider,
];

const App: React.FC = () => {
  return (
    <ComposeProvider providers={providers}>
      <Routes />
    </ComposeProvider>
  );
};

In previous versions of the documentation, the documentation said that the prop should be called providers but the code expected components. This has been fixed in version 1.0.4. And ComposeProvider now accepts either providers or components as a prop. Sorry for the inconvenience.

Package Sidebar

Install

npm i @evanion/compose

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

9.21 kB

Total Files

15

Last publish

Collaborators

  • evanion86