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 && (