fix gallery under SSR

This commit is contained in:
Chuck Dries 2022-11-04 23:40:04 -07:00
parent 01039a54e7
commit bc3249c061
No known key found for this signature in database
GPG Key ID: A00B7AEAE1DC5BE6

View File

@ -34,6 +34,10 @@ const MasonryGallery = ({
debugRating, debugRating,
linkState, linkState,
}: MasonryGalleryProps) => { }: MasonryGalleryProps) => {
const [isClient, setIsClient] = React.useState(false);
React.useEffect(() => {
setIsClient(true)
}, [])
const breakpoints = React.useMemo( const breakpoints = React.useMemo(
() => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints), () => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints),
[aspectTargetsByBreakpoint] [aspectTargetsByBreakpoint]
@ -43,13 +47,12 @@ const MasonryGallery = ({
breakpoints breakpoints
); );
const { const { observe, width, currentBreakpoint } = useDimensions({
observe,
width: containerWidth,
currentBreakpoint: breakpoint,
} = useDimensions({
breakpoints, breakpoints,
}); });
const breakpoint = currentBreakpoint.length ? currentBreakpoint : "xs";
const containerWidth = width ? width : 320;
// console.log( // console.log(
// "🚀 ~ file: MasonryGallery.tsx ~ line 47 ~ currentBreakpoint", // "🚀 ~ file: MasonryGallery.tsx ~ line 47 ~ currentBreakpoint",
// currentBreakpoint // currentBreakpoint
@ -113,7 +116,10 @@ const MasonryGallery = ({
let cursor = 0; let cursor = 0;
return ( return (
<div <div
className="flex items-center flex-wrap sm:container mx-auto" className={classNames(
"flex items-center flex-wrap mx-auto",
isClient ? "sm:container" : "max-w-[320px]"
)}
ref={observe} ref={observe}
style={{ style={{
position: "relative", position: "relative",