From c1012e57d59c32ffefe93cb1265765d68eec55d1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 23 Nov 2020 13:28:43 -0800 Subject: [PATCH] fix bug linking directly to a specific list --- src/app/UserItemsPage.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/app/UserItemsPage.js b/src/app/UserItemsPage.js index 6b02ba7..9344bc0 100644 --- a/src/app/UserItemsPage.js +++ b/src/app/UserItemsPage.js @@ -411,8 +411,18 @@ function ClosetList({ closetList, isCurrentUser, showHeading }) { return aName.localeCompare(bName); }); + // When this mounts, scroll it into view if it matches the location hash. + // This works around the fact that, while the browser tries to do this + // natively on page load, the list might not be mounted yet! + const anchorId = `list-${closetList.id}`; + React.useEffect(() => { + if (document.location.hash === "#" + anchorId) { + document.getElementById(anchorId).scrollIntoView(); + } + }, [anchorId]); + return ( - + {showHeading && (