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 betweentrue and false.
Returns: boolean - The new value (opposite of the previous value)
setTrue
Sets the value totrue.
Returns: true
setFalse
Sets the value tofalse.
Returns: false
reset
Resets the boolean to its initial value. Returns:boolean - The initial value
Basic Usage
Advanced Usage
Modal State Management
Feature Flags
Form Field State
Loading States
Visibility Toggles
Permission Checks
Using with Atom Methods
SinceBooleanAtom extends Atom, you can use standard atom methods:
Notes
- Default initial value is
false toggle()returns the new value after togglingsetTrue()andsetFalse()return the literal typestrueandfalserespectivelyreset()returns to the initial value provided during creation- All operations trigger reactive updates
- Direct assignments like
booleanAtom() = truewill not work; use the provided methods orset()