🚀 Socket Launch Week 🚀 Day 1: Introducing .NET Support in Socket.Learn More

react-curry

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-curry

react stateless component curry

1.0.9
Version published
Weekly downloads
9
200%
Maintainers
1
Weekly downloads
 
Created

inspired by curry in functional programming

intro

because react component always contains only one parameter which is props, my curry function's work is to deep merge props.

how to install

npm install --save react-curry

demo

let us make an Original component

when you want write some similar components.

these component show green border when selected

import React from 'react';
import curry from 'react-curry';

// component which will show green border when pass selected = true
const GreenBox = ({selected, InnerComponent, innerProps, size}) => (
	<div 
		style={{
			border: selected ? 'solid 2px #1fbd87' : undefined,
			width: size.width,
			height: size.height,
			display: 'flex',
			alignItems: 'center',
			justifyContent: 'center'
		}}>
		{
			<InnerComponent selected={selected} {...innerProps} />
		}
	</div>
);

// Green box with inner text
const TextGreenBox = curry(GreenBox, {
	InnerComponent: ({text, selected}) => <p style={{color: selected ? '#1fbd87' : '#666666'}}>{text}</p>,
	size: {
		height: '42px',
		width: '123px'
	}
});

// Green box with inner img
const ImgGreenBox = curry(GreenBox, {
	InnerComponent: ({imgSrc}) => <img src={imgSrc} style={{ width: '100px' }} />,,
	size: {
		height: '128px',
		width: '128px'
	}
});

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')
)

dependencies

using lodash merge function, will remove this dependency if stars more than 200 react

Keywords

FAQs

Package last updated on 11 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts