with-toggle

0.1.0 • Public • Published

withToggle

A lightweight, minimal react higher order component. That will generate state and handlers that will be passed down as props to the wrapped component.

Installation

Use npm or yarn.

yarn add with-toggle
npm i -s with-toggle

Api

withToggle

asterik for mandatory props
Param Type Default Description
name* string key for values on props
value boolean false default value
override boolean should the auto generated handler be replaced with the passed handler
handler Function a function that can act as a pre change hook or a function that will act as a handler and return the given state
Basic usage with strings
...
export default withToggle('open', 'toggled')(ComponentName);
Basic usage with objects
...
export default withToggle(
  {
    name: 'open',
    value: false,
  },
  {
    name: 'open',
    value: false,
  },
)(ComponentName);

Readme

Keywords

none

Package Sidebar

Install

npm i with-toggle

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

21.8 kB

Total Files

6

Last publish

Collaborators

  • andrewmusgrave