From 59d1944fb70c79e43869b46c7a639973a9d42c76 Mon Sep 17 00:00:00 2001 From: Innei Date: Sat, 20 Jan 2024 13:23:05 +0800 Subject: [PATCH] feat: lazyload image Signed-off-by: Innei --- src/app/(app)/(home)/page.tsx | 24 +++++++----- .../ui/markdown/renderers/image.tsx | 39 +++++++++++-------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/app/(app)/(home)/page.tsx b/src/app/(app)/(home)/page.tsx index 9d1d8820af..da10390c56 100644 --- a/src/app/(app)/(home)/page.tsx +++ b/src/app/(app)/(home)/page.tsx @@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/react-query' import React, { createElement, forwardRef, useCallback, useRef } from 'react' import clsx from 'clsx' import { m, useInView } from 'framer-motion' +import Image from 'next/image' import Link from 'next/link' import type { LinkModel } from '@mx-space/api-client' import type { PropsWithChildren } from 'react' @@ -182,15 +183,20 @@ const Welcome = () => { - Site Owner Avatar +
+ Site Owner Avatar +
= memo(({ src }) => { const imageEl = useRef(null) const wGreaterThanH = width && height ? width > height : true + const ImageComponent = height && width ? Image : 'img' + return (
= memo(({ src }) => { backgroundColor: accent, }} > - { - if (!imageEl.current) return - mediumZoom(imageEl.current).open() - }} - /> + + { + if (!imageEl.current) return + mediumZoom(imageEl.current).open() + }} + /> +
) })