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

后端 未结 12 1254
轻奢々
轻奢々 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:11

    you need to add # before your root element id.

    import React from 'react';
    import Modal from 'react-modal';
    
    
    Modal.setAppElement('#root');
    
    const OptionModal = (props) => (
      
        

    Selected Option

    {props.selectedOption &&

    {props.selectedOption}

    }
    ); export default OptionModal;

    here is the reference: http://reactcommunity.org/react-modal/accessibility/

提交回复
热议问题