0.0.1 • Published 7 years ago

react-component-strategy-map v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

react-componet-strategy-map

A react component for rendering the correct component from a strategy map based on the given key.

How to use

Add to your package.json:

yarn add react-component-strategy-map

Import and use:

import { RenderComponentStrategy } from 'react-component-strategy-map';

const componentStrategyMap = {
  someKey: SomeComponent,
  someOtherKey: SomeOtherComponent,
};

const MainComponent = () => (
  <RenderComponentStrategy
    componentStrategy={componentStrategyMap}
    componentKey="someKey"
    renderDefault={() => <div>Rendered default</div>}
  />
);

Available Props:

PropOptionalTypeDefaultDescription
componentStrategyfalse{key: string: React.ComponentType}{}Map of components used to render based on the given "componentKey"
componentKeyfalsestring""key to the desired component to render from "componentStrategy"
componentPropstrueobject{}And object of props to spread onto the rendered component
renderDefaulttrueReact.ComponentTypenullReact component to render if "componentKey" does not match a key in "componentStrategy". If no default is given, component will return null