Skip to main content

onChange

Description

Fires when the state of the Two State button changes

Usage

onChange?: (ev: { value: boolean }) => void;

Parameters

The callback of the event takes an object with the following parameter:

  • value - (required) defines if the button is pressed ("true") or unpressed ("false")

Example

function handleChange({ value }: { value: boolean }) {
console.log(value);
}

<TwoState onChange={handleChange} />

Details

The handler function receives an object with the button state which can be "true" or "false".

Related article: Catching the change of selected options