react-pdf-highlighter
react-pdf-highlighter copied to clipboard
Why use scrollRef instead of ref?
I'm new to React so this is a question for my benefit. Is there a reason to use scrollRef to get at the scrollTo method of PdfHighlighter, rather than use a ref?
I have been trying to convert the component example into function based and I am struggling to work out what to pass the scrollRef when doing so. Is it possible to explain?
I'm a React newbie, but instead of using scrollRef I ended up passing in a ref
<PdfHighlighter
ref={pdfHighlighter}
...
where pdfHighlighter is defined as
const pdfHighlighter = useRef(null)
const getHighlightById = id => state.highlights.find(highlight => highlight.id === id)
const scrollToHighlightFromHash = () => {
const highlight = getHighlightById(parseIdFromHash());
if (highlight) {
pdfHighlighter.current.scrollTo(highlight);
}
};
@AustenLamacraft thank you! You saved my day!
@AustenLamacraft You are a genius!