Boolean Helpers API reference for Boolean Helpers in Semantic UI's reactivity system toggle-left Guide

Boolean Helpers

Boolean Helpers are methods available on ReactiveVar instances that contain boolean values. These helpers provide a convenient way to toggle the state of a boolean reactive variable.

toggle

Switches the boolean value of the ReactiveVar to its opposite state.

Syntax

reactiveVar.toggle()

Returns

boolean - The new value after toggling.

Usage

import { ReactiveVar } from '@semantic-ui/reactivity';
const isActive = new ReactiveVar(false);
console.log(isActive.get()); // Output: false
isActive.toggle();
console.log(isActive.get()); // Output: true
isActive.toggle();
console.log(isActive.get()); // Output: false

Notes

  • The toggle() method is particularly useful for managing binary states in your application, such as showing/hiding elements, enabling/disabling features, or switching between two modes.
  • It provides a clean and readable way to flip boolean states without explicitly checking and setting the opposite value.
  • Remember that like all ReactiveVar modifications, using toggle() will trigger any reactive computations that depend on this variable.