Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ export function App() {

const scrollViewerTo = useRef((highlight: IHighlight) => {});

const getHighlightById = useCallback(
(id: string) => highlights.find((h) => h.id === id),
[highlights],
);

const scrollToHighlightFromHash = useCallback(() => {
const highlight = getHighlightById(parseIdFromHash());
if (highlight) {
scrollViewerTo.current(highlight);
}
}, []);
if (highlight) scrollViewerTo.current(highlight);
}, [getHighlightById]);

useEffect(() => {
window.addEventListener("hashchange", scrollToHighlightFromHash, false);
Expand All @@ -87,10 +90,6 @@ export function App() {
};
}, [scrollToHighlightFromHash]);

const getHighlightById = (id: string) => {
return highlights.find((highlight) => highlight.id === id);
};

const addHighlight = (highlight: NewHighlight) => {
console.log("Saving highlight", highlight);
setHighlights((prevHighlights) => [
Expand Down