Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-curry

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-curry

react stateless component curry

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
increased by2000%
Maintainers
1
Weekly downloads
 
Created
Source

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc