main
Last change
on this file since 5d6f37a was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 7 weeks ago |
add customer
|
-
Property mode
set to
100644
|
File size:
731 bytes
|
Line | |
---|
1 | 'use client';
|
---|
2 |
|
---|
3 | import { useCallback, useState } from 'react';
|
---|
4 |
|
---|
5 | // ----------------------------------------------------------------------
|
---|
6 |
|
---|
7 | interface ReturnType {
|
---|
8 | value: boolean;
|
---|
9 | onTrue: () => void;
|
---|
10 | onFalse: () => void;
|
---|
11 | onToggle: () => void;
|
---|
12 | setValue: React.Dispatch<React.SetStateAction<boolean>>;
|
---|
13 | }
|
---|
14 |
|
---|
15 | export function useBoolean(defaultValue?: boolean): ReturnType {
|
---|
16 | const [value, setValue] = useState(!!defaultValue);
|
---|
17 |
|
---|
18 | const onTrue = useCallback(() => {
|
---|
19 | setValue(true);
|
---|
20 | }, []);
|
---|
21 |
|
---|
22 | const onFalse = useCallback(() => {
|
---|
23 | setValue(false);
|
---|
24 | }, []);
|
---|
25 |
|
---|
26 | const onToggle = useCallback(() => {
|
---|
27 | setValue((prev) => !prev);
|
---|
28 | }, []);
|
---|
29 |
|
---|
30 | return {
|
---|
31 | value,
|
---|
32 | onTrue,
|
---|
33 | onFalse,
|
---|
34 | onToggle,
|
---|
35 | setValue,
|
---|
36 | };
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.