Skip to content

Repository files navigation

Inferno JS Logo

Incompose

Incompose is a Inferno.js clone of the famous recompose lib for React.

Build Statusnpm versionnpm downloadsCode ClimateTest CoverageMIT

Installation

npm install incompose

Support

Following HoCs are available. If you miss any helper/HoC please send me a note on twitter @roman_zanettin or create an issue / open a PR. Thanks.

Functionsince
branch0.0.8
compose0.0.3
createSink0.0.6
defaultProps0.0.3
flattenProps0.0.4
nest0.0.7
pure0.0.8
renderComponent0.0.8
renderNothing0.0.5
renameProp0.0.4
renameProps0.0.4
shouldUpdate0.0.3
withHandlers0.0.5
withLifecycle0.0.3
withProps0.0.3
withPropsOnChange0.0.6
withReducer0.0.7
withState0.0.3

Usage

Please find the API and example code in the docs folder.

Import

Incompose provides named and default imports:

import{withState}from'incompose';importwithStatefrom'incompose/dist/withState';

Example

import{defaultasInferno,linkEvent}from'inferno';import{compose,withState,shouldUpdate}from'incompose';constinc=(props)=>{props.setCount(props.count+=1);};constdec=(props)=>{props.setCount(props.count-=1);};constCounter=(props)=>(<div><h1>count : {props.count}</h1><buttononClick={linkEvent(props,dec)}>-</button><buttononClick={linkEvent(props,inc)}>+</button></div>);/** * with state creates 2 new props on the component props * props.count -	contains the value (1 is set as default value) * props.setCount	-	contains the setter function */constwithCounterState=withState('count','setCount',1);/** * should update prevents the component of re-render (shouldUpdate lifecycle hook) * you can compare current and next props and decide whether the component * should update or not. In this example, the counter just updates if * props.count is even. */constwithUpdatePolicy=shouldUpdate((props,nextProps)=>(nextProps.count%2===0));/** * with compose all the extended functions are composed BEFORE Counter * gets rendered. Please not that order matters. */exportdefaultcompose(withCounterState,withUpdatePolicy,)(Counter);

Thanks

Special thanks to all the contributors and Andrew Clark (@acdlite) for creating this amazing lib for React!

Changelog

Changelog is available here.

About

A inferno utility belt for function components and higher-order components

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages