In order to resolve the error “TypeError: Cannot read property ‘getBoundingClientRect’ of null”, you’ll need to make some adjustments in your code. Specifically, ensure that ‘pdfWrapper’ exists and has a ‘current’ property before using it, as demonstrated in the below code snippet:

const setPdfSize = () => {
   // check if 'pdfWrapper' exists and has a 'current' property before using it
    if (pdfWrapper?.current) { 
      setInitialWidth(pdfWrapper.current.getBoundingClientRect().width);
    }
  };

Support On Demand!

                                         
ReactJS