From e0204615a72b288cba13d85a3dd6779a57714d08 Mon Sep 17 00:00:00 2001 From: tangly Date: Sun, 13 Nov 2022 11:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/hexo/components/BlogPostListScroll.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/themes/hexo/components/BlogPostListScroll.js b/themes/hexo/components/BlogPostListScroll.js index 828e58aa..ca6f705d 100644 --- a/themes/hexo/components/BlogPostListScroll.js +++ b/themes/hexo/components/BlogPostListScroll.js @@ -3,7 +3,7 @@ import BlogPostCard from './BlogPostCard' import BlogPostListEmpty from './BlogPostListEmpty' import { useGlobal } from '@/lib/global' import throttle from 'lodash.throttle' -import React, { useCallback, useEffect, useRef, useState } from 'react' +import React from 'react' import CONFIG_HEXO from '../config_hexo' import { getListByPage } from '@/lib/utils' @@ -16,7 +16,7 @@ import { getListByPage } from '@/lib/utils' */ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HEXO.POST_LIST_SUMMARY }) => { const postsPerPage = BLOG.POSTS_PER_PAGE - const [page, updatePage] = useState(1) + const [page, updatePage] = React.useState(1) const postsToShow = getListByPage(posts, page, postsPerPage) let hasMore = false @@ -31,7 +31,7 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HE } // 监听滚动自动分页加载 - const scrollTrigger = useCallback(throttle(() => { + const scrollTrigger = React.useCallback(throttle(() => { const scrollS = window.scrollY + window.outerHeight const clientHeight = targetRef ? (targetRef.current ? (targetRef.current.clientHeight) : 0) : 0 if (scrollS > clientHeight + 100) { @@ -40,14 +40,14 @@ const BlogPostListScroll = ({ posts = [], currentSearch, showSummary = CONFIG_HE }, 500)) // 监听滚动 - useEffect(() => { + React.useEffect(() => { window.addEventListener('scroll', scrollTrigger) return () => { window.removeEventListener('scroll', scrollTrigger) } }) - const targetRef = useRef(null) + const targetRef = React.useRef(null) const { locale } = useGlobal() if (!postsToShow || postsToShow.length === 0) {