@karsegard/react-compose

1.3.2 • Public • Published

React-compose

Introduction

This is a collection of Higher Order Function that helps to compose React components

Concept

modifiers

Modifiers are props that will be converted to a class

variables

Variables are props that will be converted to styles

API

  • withModifiers(namer[Function], modifiers[Array]) Generate a new component that will accept Props presents in the modifiers Array. For each passed prop it will call the namer function

  • withVariables = (keyEnhancer[Function], valEnhancer[Function], variables[Array])

  • keyEnhancer = prop, value, all props => new key

  • valueEnhancer = value => value

Re-usable & composable Properties

For example, you want to create components That support getting a grid area.

import {withVariables,withBaseClass} from  '@karsegard/react-compose'

export  const  withGridArea  =  withVariables(
			_  =>  `gridArea`,
			x  =>  `${x}`,
			['area']
);


export  const  ComponentWithArea  =  compose(
	withGridArea,
	withBaseClass('area-component')
)(divElement);

// somewhere Else
...
let MyComponentWithArea = withArea(MyExistingComponent)
return (<MyComponentWithArea area="header"/>)

Install

yarn add @karsegard/react-compose

Usage

see example

License

MIT © FDT2k

Readme

Keywords

none

Package Sidebar

Install

npm i @karsegard/react-compose

Weekly Downloads

71

Version

1.3.2

License

MIT

Unpacked Size

510 kB

Total Files

16

Last publish

Collaborators

  • fdt2k