|
1
|
import { HookValues } from "@/components/HookValues" |
|
2
|
import { ComponentExample } from "@/components/ComponentExample" |
|
3
|
|
|
4
|
export const metadata = { |
|
5
|
title: `useToggleState`, |
|
6
|
} |
|
7
|
|
|
8
|
# {metadata.title} |
|
9
|
|
|
10
|
This hook tracks a boolean value and toggles between its two states. |
|
11
|
|
|
12
|
This guide explains how to use the `useToggleState` hook. |
|
13
|
|
|
14
|
For example, you can use this hook to display a checkbox or a [Switch](../../components/switch/page.mdx) that toggles a [Focus Modal](../../components/focus-modal/page.mdx). |
|
15
|
|
|
16
|
<ComponentExample name="use-toggle-state-demo" hideFeedback /> |
|
17
|
|
|
18
|
## Usage |
|
19
|
|
|
20
|
```tsx |
|
21
|
import { useToggleState } from "@medusajs/ui" |
|
22
|
``` |
|
23
|
|
|
24
|
```tsx |
|
25
|
const [state, open, close, toggle] = useToggleState() |
|
26
|
``` |
|
27
|
|
|
28
|
--- |
|
29
|
|
|
30
|
## API Reference |
|
31
|
|
|
32
|
### useToggleState Parameters |
|
33
|
|
|
34
|
<HookValues hook="useToggleStateProps" /> |
|
35
|
|
|
36
|
### useToggleState Return Value |
|
37
|
|
|
38
|
<HookValues hook="useToggleStateReturn" hideFeedback /> |