“Warning: react-modal: App element is not defined. Please use `Modal.setAppElement(el)` or set `appElement={el}`”

后端 未结 12 1233
轻奢々
轻奢々 2021-02-07 03:36

How to fix this warning in console of a React app using the react-modal package:

Warning: react-modal: App element is not defined. Please use Moda

12条回答
  •  攒了一身酷
    2021-02-07 04:30

    This is my TypeScript Modal component which wraps react-modal v3.8.1:

    import React from 'react'
    import ReactModal from 'react-modal'
    
    interface Props {
      isOpen: boolean
      ariaLabel?: string
    }
    
    const Modal: React.FC = ({
      children,
      ariaLabel = 'Alert Modal',
      isOpen,
    }) => (
      
        {children}
      
    )
    
    export default Modal
    

    Usage in component with state = { isOpen: true }:

    
      

    Modal Content here…

提交回复
热议问题