https://github.com/drapegnik/react-use-duplex
React hook for duplex buttons state
https://github.com/drapegnik/react-use-duplex
duplex react react-hooks switcher toggle
Last synced: about 1 month ago
JSON representation
React hook for duplex buttons state
- Host: GitHub
- URL: https://github.com/drapegnik/react-use-duplex
- Owner: Drapegnik
- License: mit
- Created: 2018-10-27T21:55:34.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-09T10:16:56.000Z (over 7 years ago)
- Last Synced: 2025-03-13T19:04:54.260Z (over 1 year ago)
- Topics: duplex, react, react-hooks, switcher, toggle
- Language: JavaScript
- Homepage: https://codesandbox.io/s/0yzxqry6pp
- Size: 3.91 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `react-use-duplex`
> React hook for duplex buttons state
[](https://gyazo.com/06f2e4f7c95fe42f1e0d111d49bc784e) [](https://gyazo.com/3602542c34219b7917b5c8ef14b9f3fc)
> **Note:** This is using the new [React Hooks API Proposal](https://reactjs.org/docs/hooks-intro.html)
> 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
```sh
npm i react-use-duplex
```
## Usage
```jsx
import useDuplex from 'react-use-duplex';
const MyComponent = () => {
const { state, handleLeft, handleRight } = useDuplex({
initialState: 'left', // optional
});
return (
{state === 'left' ? 'Approved 👍' : 'Approve'}
{state === 'right' ? 'Rejected 👎' : 'Reject'}
);
};
```
## Example
[Open in CodeSandbox](https://codesandbox.io/s/0yzxqry6pp)