btholt / citr-v6-project

Project files for the Complete Intro to React v6, as taught for Frontend Masters
Apache License 2.0
482 stars 458 forks source link

Modal Error #20

Open MaiRizk opened 2 years ago

MaiRizk commented 2 years ago

This error is there when I try to showModal using Modal.js Uncaught TypeError: Cannot read properties of null (reading 'appendChild') at Modal.js:13

RaminMammadzada commented 2 years ago

The same issue is in my local as well.

UPDATE: The solution I found is to defend against the possibility of elRef.current being null. Just add the line to if block:

    if(elRef.current) {
      modalRoot.appendChild(elRef.current);
    }