react-use-duplex
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

react-use-duplex

React hook for duplex buttons state

Image from Gyazo Image from Gyazo

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

npm i react-use-duplex

Usage

import useDuplex from 'react-use-duplex';

const MyComponent = () => {
  const { state, handleLeft, handleRight } = useDuplex({
    initialState: 'left', // optional
  });

  return (
    <div>
      <button onClick={handleLeft}>
        {state === 'left' ? 'Approved 👍' : 'Approve'}
      </button>
      <button onClick={handleRight}>
        {state === 'right' ? 'Rejected 👎' : 'Reject'}
      </button>
    </div>
  );
};

Example

Open in CodeSandbox

Package Sidebar

Install

npm i react-use-duplex

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

4.95 kB

Total Files

6

Last publish

Collaborators

  • drapegnik