alex-cory/react-useportal

External Method to closePortal

jasonlor opened this issue · 1 comments

I'm currently using React Hooks and stateless functional components.

If I add closePortal to <button onClick , it will always close the portal and invalidate the onSubmit event.
If I add closePortal to a <button onSubmit, the portal doesn't close.
Is there a function that I can call to close the Portal?

Thanks!

Figured it out from the codepens.

const { openPortal: openFirstPortal, closePortal: closeFirstPortal, isOpen: isFirstOpen, Portal: FirstPortal } = usePortal()

Assigning a variable to closePortal will allow you to use it as a function

closeFirstPortal() will trigger a close event.

Thanks!