@ogre-tools/injectable-react
TypeScript icon, indicating that this package has built-in type declarations

17.11.1 • Public • Published

Dependency injection for React in Ogre Tools

A brutal component for injecting components that use injectable.

Usage

$ npm install @ogre-tools/injectable
$ npm install @ogre-tools/injectable-react
...

import { withInjectables } from '@ogre-tools/injectable-react';

Usage

it('given a Component is registered, when Inject is rendered for the Component, renders with dependencies', () => {
  const di = createContainer();


  const NonInjectedTestComponent = ({ someDependency, ...props }) => (
    <div {...props}>Some content: "{someDependency}"</div>
  );

  const TestComponent = withInjectables(NonInjectedTestComponent, {
    getProps: (di, props) => ({
      someDependency: 'some-value',
      ...props,
    }),
  });

  const actual = mount(
    <DiContextProvider value={{ di }}>
      <TestComponent some-prop="some-other-prop" />
    </DiContextProvider>,
  );

  expect(actual).toHaveText('Some content: "some-value"');
});

Documentation

Check unit tests for documentation.

Package Sidebar

Install

npm i @ogre-tools/injectable-react

Weekly Downloads

170

Version

17.11.1

License

MIT

Unpacked Size

8.58 kB

Total Files

5

Last publish

Collaborators

  • iku-turso
  • jansav