0.1.0 • Published 6 years ago

react-use-duplex v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

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