Custom hook to toggle between two items. By default, it toggles between false and true. But you can pass in any two items to toggle between.
false
true
The type of items to toggle between.
The two items to toggle between.
The initial item.
A tuple containing the current item and a function to toggle between the items, optionally going to a specific item.
const [open, setOpen] = useToggle();const [answer, toggleAnswer] = useToggle(["yes", "no"], "no"); Copy
const [open, setOpen] = useToggle();const [answer, toggleAnswer] = useToggle(["yes", "no"], "no");
Optional
Custom hook to toggle between two items. By default, it toggles between
false
andtrue
. But you can pass in any two items to toggle between.Template: T
The type of items to toggle between.
Param: items
The two items to toggle between.
Param: initialItem
The initial item.
Returns
A tuple containing the current item and a function to toggle between the items, optionally going to a specific item.
Example