Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benpptung/react-children-with
return children with new props merged
https://github.com/benpptung/react-children-with
props react react-children
Last synced: about 2 months ago
JSON representation
return children with new props merged
- Host: GitHub
- URL: https://github.com/benpptung/react-children-with
- Owner: benpptung
- Created: 2017-05-28T08:32:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-13T07:59:22.000Z (almost 7 years ago)
- Last Synced: 2024-11-07T05:04:15.577Z (2 months ago)
- Topics: props, react, react-children
- Language: JavaScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-children-with
send new props to children in React.
## Installation
`npm install -S react-children-with`
## Example
Instead of
```
const React = require('react');var children = React.Children.map(this.props.children, child=> {
return React.cloneElement(child, new_props);
})```
Just write
```
const merge = require('react-children-with');var children = merge(this.props.children, new_props);
```
or Instead of
```
const React = require('react');var children = React.Children.map(this.props.children, child=> {
return [Apple, Orange].indexOf(child.type) >= 0 ?
React.cloneElement(child, new_props) : child;
})
```just write
```
const merge = require('react-children-with');var children = merge(this.props.children, new_props, [Apple, Orange]);
```## merge.deep()
same as merge(), but it can merge props to grand child, or grand's grand child....```
```
in Parent, merge new_props to `GrandChild` and skip `Child`
```
const merge = require('react-children-with').deep;var children = merge(props.children, {onSelect}, [GrandChild]);
```