Skip to content

fix: add dependency highlights in function callback scrollToHighlight… #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export function App() {
const scrollViewerTo = useRef((highlight: IHighlight) => {});

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

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

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

Expand Down
Loading