react-curry
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "react-curry", | ||
"version": "1.0.7", | ||
"description": "react stateless curry", | ||
"version": "1.0.8", | ||
"description": "react stateless component curry", | ||
"main": "./lib/index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -5,3 +5,3 @@ inspired by curry in functional programming | ||
because react component always contains only one parameter which is props, my curry | ||
function's work is to deep merge two props. | ||
function's work is to deep merge props. | ||
@@ -13,7 +13,12 @@ ## how to install | ||
## use case | ||
## demo | ||
let us make an Original component | ||
``` | ||
``` | ||
when you want write some similar components. | ||
<img style="width: 100px" src="./water.png"/> | ||
<img style="width: 100px" src="./google.png"/> | ||
@@ -59,2 +64,10 @@ these component show green border when selected | ||
}); | ||
React.render( | ||
<div> | ||
<TextGreenBox selected={true} innerProps={{text: '西瓜'}}/> | ||
<ImgGreenBox selected={true} innerProps={{imgSrc: 'https://www.google.com.hk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'}}/> | ||
</div>, | ||
document.getElementById('root') | ||
) | ||
``` | ||
@@ -61,0 +74,0 @@ |
import React from 'react'; | ||
import {merge} from 'lodash'; | ||
import { merge } from 'lodash'; | ||
export default (Component, obj) => ( | ||
(props) => <Component {...merge(obj, props)}/> | ||
); | ||
export default (ComponentOrElementName, preProps) => { | ||
const merged = { ...merge(preProps, props) }; | ||
return (typeof ComponentOrElementName === 'string') | ||
? (props) => React.createElement(ComponentOrElementName, merged) | ||
: (props) => <Component {...merged} /> | ||
}; |
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
42918
8
76