@dprovodnikov/use-toggle

1.0.4 • Public • Published

useToggle

Intent

This react hook extracts toggle behaviour so you can only focus on the appearance of your components.

Usage example

import React from 'react';
import useToggle from '@dprovodnikov/use-toggle';

const Toggle = function () {
  const handleChange = value => console.log('Toggle has changed its value to', value);

  const [isOn, toggle] = useToggle(false, handleChange);

  return (
    <button onClick={toggle}>
      {isOn ? 'Turn off' : 'Turn on'}
    </button>
  );
};

export default Toggle;

The hooks takes a default value as the first argument, and a change listener function as the second.

Install

$ npm i @dprovodnikov/use-toggle

Requirements

  • React^16.8

License

MIT

Package Sidebar

Install

npm i @dprovodnikov/use-toggle

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

3.7 kB

Total Files

6

Last publish

Collaborators

  • dprovodnikov