import { siteConfig } from '@/lib/config' import { RecentComments } from '@waline/client' import SmartLink from '@/components/SmartLink' import { useEffect, useState } from 'react' /** * 最近评论列表 * 基于Waline实现 * @see https://waline.js.org/guide/get-started.html * @param {*} props * @returns */ const RecentCommentListForExample = props => { const [comments, updateComments] = useState([]) const [onLoading, changeLoading] = useState(true) useEffect(() => { RecentComments({ serverURL: siteConfig('COMMENT_WALINE_SERVER_URL'), count: 5 }).then(({ comments }) => { changeLoading(false) updateComments(comments) }) }, []) return ( <> {onLoading && (
Loading...
)} {!onLoading && comments && comments.length === 0 && (
No Comments
)} {!onLoading && comments && comments.length > 0 && comments.map(comment => (
--{comment.nick}
))} ) } export default RecentCommentListForExample