Skip to main content

Overview

reatomBoolean creates an atom that manages boolean state with built-in methods for common boolean operations like toggle, setTrue, setFalse, and reset.

Import

Type Signature

Parameters

boolean
default:"false"
The initial boolean value
string
default:"'booleanAtom'"
Optional name for the atom, useful for debugging

Methods

toggle

Toggles the boolean value between true and false. Returns: boolean - The new value (opposite of the previous value)

setTrue

Sets the value to true. Returns: true

setFalse

Sets the value to false. Returns: false

reset

Resets the boolean to its initial value. Returns: boolean - The initial value

Basic Usage

Advanced Usage

Feature Flags

Form Field State

Loading States

Visibility Toggles

Permission Checks

Using with Atom Methods

Since BooleanAtom extends Atom, you can use standard atom methods:

Notes

  • Default initial value is false
  • toggle() returns the new value after toggling
  • setTrue() and setFalse() return the literal types true and false respectively
  • reset() returns to the initial value provided during creation
  • All operations trigger reactive updates
  • Direct assignments like booleanAtom() = true will not work; use the provided methods or set()