DanielArnould / react-pdf-highlighter-extended

📄 Set of modern React components for PDF highlighting
https://danielarnould.github.io/react-pdf-highlighter-extended/example-app/
MIT License
43 stars 16 forks source link

AutoScroll to hash throws error, Cannot read properties of null (reading 'container') #7

Closed alexmagwe closed 4 months ago

alexmagwe commented 4 months ago

this error occurs when i try to auto scroll to a specific hash when the page loads when navigating from another page with the hash id in the URL. this is the code that does the auto scrolling:

     useEffect(() => {
             if (!highlighterUtilsRef.current || highlights.length === 0) {
             return
          }
          const scrollToHighlightFromHash = () => {
             const highlight = getHighlightById(parseIdFromHash())

          if (highlight && highlighterUtilsRef?.current) {
            highlighterUtilsRef.current.scrollToHighlight(highlight)
            }
         }
    scrollToHighlightFromHash()
}, [getHighlightById, activeHighlight, highlights])
alexmagwe commented 4 months ago

the solution is to make sure the useEffect is called within the pdfhighlighter context