{"id":8944,"date":"2023-11-08T07:26:45","date_gmt":"2023-11-08T07:26:45","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=8944"},"modified":"2023-11-08T07:26:45","modified_gmt":"2023-11-08T07:26:45","slug":"react-pdf-responsiveness-using-react-hooks","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react\/react-pdf-responsiveness-using-react-hooks","title":{"rendered":"When increasing or decreasing window size using react-pdf, I get this error \u201cTypeError: Cannot read property \u2018getBoundingClientRect\u2019 of null\u201d"},"content":{"rendered":"<p>In order to resolve the error <strong>\u201cTypeError: Cannot read property \u2018getBoundingClientRect\u2019 of null\u201d<\/strong>, you\u2019ll need to make some adjustments in your code. Specifically, ensure that &#8216;pdfWrapper&#8217; exists and has a &#8216;current&#8217; property before using it, as demonstrated in the below code snippet:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">const setPdfSize = () =&gt; {\r\n   \/\/ check if 'pdfWrapper' exists and has a 'current' property before using it\r\n    if (pdfWrapper?.current) { \r\n      setInitialWidth(pdfWrapper.current.getBoundingClientRect().width);\r\n    }\r\n  };\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In order to resolve the error \u201cTypeError: Cannot read property \u2018getBoundingClientRect\u2019 of null\u201d, you\u2019ll need to make some adjustments in your code. Specifically, ensure that &#8216;pdfWrapper&#8217; exists and has a &#8216;current&#8217; property before using it, as demonstrated in the below code snippet: const setPdfSize = () =&gt; { \/\/ check if &#8216;pdfWrapper&#8217; exists and has [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8945,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8944","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8944"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=8944"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8944\/revisions"}],"predecessor-version":[{"id":8947,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8944\/revisions\/8947"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8945"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=8944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=8944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=8944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}