Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

Commit

Permalink
Add examples for renameProp and renameProps (#765)
Browse files Browse the repository at this point in the history
Following the issue #337, I've decided add examples for renameProp and renameProps.
  • Loading branch information
RodolfoSilva authored and istarkov committed Dec 3, 2018
1 parent 09f9ec6 commit 3db12ce
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ renameProp(

Renames a single prop.

Example:

```js
const enhance = compose(
withProps({ 'loadingDataFromApi': true, 'posts': [] }),
renameProp('loadingDataFromApi', 'isLoading'),
renameProp('posts', 'items'),
);

const Posts = enhance(({ isLoading, items }) => (
<div>
<div>Loading: { isLoading ? 'yes' : 'no'}</div>
<ul>
{isLoading && items.map(({ id, title }) => (<li key={id}>{title}</li>))}
</ul>
</div>
));
```

### `renameProps()`

```js
Expand All @@ -206,6 +225,24 @@ renameProps(

Renames multiple props, using a map of old prop names to new prop names.

Example:

```js
const enhance = compose(
withProps({ 'loadingDataFromApi': true, 'posts': [] }),
renameProps({ 'loadingDataFromApi': 'isLoading', 'posts': 'items' }),
);

const Posts = enhance(({ isLoading, items }) => (
<div>
<div>Loading: { isLoading ? 'yes' : 'no'}</div>
<ul>
{isLoading && items.map(({ id, title }) => (<li key={id}>{title}</li>))}
</ul>
</div>
));
```

### `flattenProp()`

```js
Expand Down

0 comments on commit 3db12ce

Please sign in to comment.