Skip to main content

useToggle

The useToggle React hook useful when value must be Boolean type

Example

import {useToggle} from "@lad-tech/mobydick-utils";
import {FC} from "react";
import {Switch,SwitchChangeEvent} from "react-native";

const SwitchComponent: FC = () => {
const [toggle, setToggle] = useToggle(false);

const onChange = (event: SwitchChangeEvent) => {
setToggle(event.nativeEvent.value);
}

return <Switch value={toggle} onChange={onChange} />

}

Parameters

NAMETYPEDEFAULT
initialStatebooleanfalse

Returns

The useToggle hook returns a tuple with the following:

INDEXTYPEDESCRIPTION
0booleanCurrent state
1functionFunction to toggle state