usePromiseDisclosure
usePromiseDisclosure
is a custom hook that helps handle common open/close or toggle scenarios with promises. It can be used to control components such as Modal
, Dialog
, Drawer
, etc.
Import
import { usePromiseDisclosure } from "@yamada-ui/react"
Usage
If onClose
is executed, the internal Promise
will be rejected. Therefore, handle errors by using try...catch or Promise.prototype.catch with onOpen
.
Editable example
const { isOpen, onClose, onOpen, onSuccess } = usePromiseDisclosure() const onClick = async () => { try { // Subsequent processing will be blocked until `onSuccess` is executed. await onOpen() console.log("あるじゃねえか、サタン!!!") console.log("おめえはホントに世界の…") console.log("救世主かもな!!!!") } catch { console.error("地球は滅亡しました") } } return ( <VStack alignItems="start"> <Text>だ…大地よ海よ そして生きているすべての みんな…</Text> <Text>このオラにほんのちょっとずつだけ元気をわけてくれ…!!!</Text> <Button onClick={onClick}>わけない</Button> <Dialog size="2xl" cancel="わけない" header="ミスター・サタン" isOpen={isOpen} success="わける" onCancel={onClose} onClose={onClose} onSuccess={onSuccess} > <Text>き、きさまらいいかげんにしろーーーっ!!!</Text> <Text>さっさと協力しないかーーーっ!!!</Text> <Text> このミスター・サタンさまのたのみも、きけんというのかーーーっ!!! </Text> </Dialog> </VStack> )
Edit this page on GitHub