Skip to content

maxhallinan/reshep

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

reshep

Build Status Coverage Status

A higher-order component that "reshapes" a React component props object according to a map of from/to path strings.

An alternative to a map function when no value transformation is required.

Install

$ npm install --save reshep

Usage

import assert from 'assert';
import { shapeFrom, } from 'reshep';

const enhance = shapeFrom({
  'history.push': 'changeRoute',
  'match.params.foo': 'foo',
});

const Foo = enhance(({ changeRoute, foo, }) => {
  assert.ok(changeRoute);
  assert.ok(foo);

  /* ... */
});
import assert from 'assert';
import { shapeWith, } from 'reshep';

const enhance = shapeWith({
  'match.params.foo': 'foo',
});

const Foo = enhance(({ match, foo, }) => {
  assert.ok(foo);

  // parent props are merged with new props
  assert.ok(match.params.foo);

  /* ... */
});

API

shapeFrom(pathMap)

Takes a map of path strings and returns a higher-order component. The higher-order component picks values from the parent props and sets them on a new props object passed to the base component.

pathMap

Type: { [string]: string }

An object map of path strings. The key is a path to pick from the parent props and the value is a path to set on the base component props.

shapeWith(pathMap)

Like shapeFrom, except the new props are deeply merged with the parent props.

pathMap

The same as the pathMap argument to shapeFrom.

License

MIT © Max Hallinan

About

A higher-order component that "reshapes" a React component props object.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published