-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export useful functions from useToast
- Loading branch information
1 parent
a84b69c
commit 63530d3
Showing
4 changed files
with
37 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
import { UseToastOptions, useToast as useChakraToast } from "@chakra-ui/react" | ||
import { | ||
ToastId, | ||
UseToastOptions, | ||
useToast as useChakraToast, | ||
} from "@chakra-ui/react" | ||
import { useCallback } from "react" | ||
|
||
export function useToast(props: UseToastOptions) { | ||
return useChakraToast({ | ||
export function useToast({ | ||
id, | ||
...props | ||
}: Omit<UseToastOptions, "id"> & { id: ToastId }) { | ||
const toast = useChakraToast({ | ||
position: "top", | ||
duration: null, | ||
isClosable: true, | ||
containerStyle: { my: 1 }, | ||
...props, | ||
}) | ||
|
||
const showToast = useCallback(() => { | ||
if (!toast.isActive(id)) { | ||
toast({ | ||
id, | ||
}) | ||
} | ||
}, [id, toast]) | ||
|
||
const closeToast = useCallback(() => toast.close(id), [id, toast]) | ||
|
||
return { toast, showToast, closeToast } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters