Created
July 13, 2022 07:10
-
-
Save sairajchouhan/374a73d0b9f43b1bb8f5bc78a6f7b14a to your computer and use it in GitHub Desktop.
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
import { useState } from "react" | |
const useModal = (initial = false, duration = 300) => { | |
const [isOpen, setIsOpen] = useState(initial) | |
const closeModal = () => { | |
return new Promise((res) => { | |
setIsOpen(false) | |
setTimeout(() => { | |
res(true) | |
}, duration) | |
}) | |
} | |
const openModal = () => { | |
setIsOpen(true) | |
} | |
return { | |
isOpen, | |
closeModal, | |
openModal, | |
} | |
} | |
export default useModal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can be used to close the form and then reset the state of the contents inside of the modal, I got this issue when using @headlessui/react where the modal closes on transition for 300ms but the state was getting reset before the modal gets closed