How can I make React Portal work with React Hook?

后端 未结 7 2059
感动是毒
感动是毒 2021-01-01 22:05

I have this specific need to listen to a custom event in the browser and from there, I have a button that will open a popup window. I\'m currently using React Portal to open

7条回答
  •  情歌与酒
    2021-01-01 22:26

    You could also just use react-useportal. It works like:

    import usePortal from 'react-useportal'
    
    const App = () => {
      const { openPortal, closePortal, isOpen, Portal } = usePortal()
      return (
        <>
          
          {isOpen && (
            
              

    This is more advanced Portal. It handles its own state.{' '} , hit ESC or click outside of me.

    )} ) }

提交回复
热议问题