Playground

useToggle

Cycle through a list of values, or flip a boolean.

  • No DOM output.

Import

import '@monoline/css';
import {useToggle} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add use-toggle

Usage

import {Button, useToggle, type Demo} from '@monoline/react';

const themes = ['warm', 'dark', 'midnight'] as const;

function Demo() {
  const [theme, next] = useToggle<string>(themes as unknown as readonly [string, ...string[]]);
  return <Button onClick={() => next()}>Theme: {theme}</Button>;
}

<Demo />

Examples

Cycle

Behaviour

  • No DOM output.