# use-state-toggle

> There a lot of similar libraries out there, but they only toggle `boolean` state. This hook allows you to toggle any state, by providing custom `truthy` or `falsy` values.

Latest version **0.1.1** (published 2020-10-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-state-toggle
pnpm add use-state-toggle
yarn add use-state-toggle
bun add use-state-toggle
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2020-10-03 |
| First published | 2020-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Karl Marx Lopez |
| Maintainers | karlmarxlopez |
| Keywords | react, hook, hooks, react hook, react hooks, use state, use toggle state, use state toggle, toggle state |

## Links

- npm: https://www.npmjs.com/package/use-state-toggle
- Repository: https://github.com/karlmarxlopez/use-state-toggle
- Homepage: https://github.com/karlmarxlopez/use-state-toggle#readme
- Issues: https://github.com/karlmarxlopez/use-state-toggle/issues
- npm.io page: https://npm.io/package/use-state-toggle

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2020-10-03
- 0.1.0 — 2020-10-03

## README

# use-state-toggle

There a lot of similar libraries out there, but they only toggle `boolean` state. This hook allows you to toggle any state, by providing custom `truthy` or `falsy` values.

### Sample usage

**React Web**
```jsx
import React from 'react';
import {useStateToggle} from 'use-state-toggle';

const MyComponent = () => {
  const [switchState, toggleSwitch] = useStateToggle(false);

  const [didAccept, toggleDidAccept] = useStateToggle('no', {
    truthy: 'yes',
    falsy: 'no',
  });

  return (
    <div>
      <button onPress={toggleDidAccept}>
        Toggle Switch
      </button>
      <h1>Switch is on? {String(switchState)}</h1>

      <button onPress={toggleDidAccept}>
        Accept?
      </button>
      <h1>You said {didAccept}</h1>
    </div>
  );
};

export default MyComponent;
```

**React Native**
```tsx
import React from 'react';
import {useStateToggle} from 'use-state-toggle';
import {Text, SafeAreaView, Button} from 'react-native';

const UseToggleStateSample = () => {
  const [switchState, toggleSwitch] = useStateToggle(false);

  const [didAccept, toggleDidAccept] = useStateToggle('no', {
    truthy: 'yes',
    falsy: 'no',
  });

  return (
    <SafeAreaView style={{flex: 1}}>
      <Button onPress={toggleDidAccept} title="Accept?" />
      <Text>You said {didAccept}</Text>
      <Button onPress={toggleSwitch} title="Toggle Switch" />
      <Text>Switch is on? {String(switchState)}</Text>
    </SafeAreaView>
  );
};

export default UseToggleStateSample;

```

### License

`use-state-toggle` is MIT licensed, as found in the [LICENSE](/LICENSE) file.

---
_Source: https://npm.io/package/use-state-toggle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
