react-hoc-utils
A steady growing collection of useful higher-order components for React.
Install
npm install --save react-hoc-utils
Higher-order components
withArray()
: HigherOrderComponent
Passes three additional props to the base component: An array holding the current state, a function to add values to the array and a function to set the complete state of the array:
; const TodosView = <div> /* List */ <ul> shoppingList </ul> /* Add item */ <button onClick= >Add milk</button> /* Add multiple items at once */ <button onClick= > Add butter + avocado </button> /* Override the array */ <button onClick= >Clear</button> </div> const enhance = const Todos = ;
withRefs()
withRefs: HigherOrderComponent
Passes an additional prop to the base component named refs. Refs has a set method to assign references. To retrieve the reference the dot notation is utilized:
;; const View = <div ref= refs onClick=handleClick /> const Component = View;
Tests
npm test