fix bug linking directly to a specific list

This commit is contained in:
Emi Matchu 2020-11-23 13:28:43 -08:00
parent 8068a1d260
commit c1012e57d5

View file

@ -411,8 +411,18 @@ function ClosetList({ closetList, isCurrentUser, showHeading }) {
return aName.localeCompare(bName); 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 ( return (
<Box id={`list-${closetList.id}`}> <Box id={anchorId}>
{showHeading && ( {showHeading && (
<Heading3 <Heading3
marginBottom="2" marginBottom="2"