移除Preact框架、引入react-hook检查

This commit is contained in:
tangly1024
2022-11-30 22:08:15 +08:00
parent c527673b84
commit 2f76a7314c
12 changed files with 54 additions and 171 deletions

View File

@@ -2,26 +2,27 @@
import BLOG from '@/blog.config'
import { useGlobal } from '@/lib/global'
import { loadExternalResource } from '@/lib/utils'
import { useEffect } from 'react'
import React from 'react'
export default function Live2D() {
if (!BLOG.WIDGET_PET || !JSON.parse(BLOG.WIDGET_PET)) {
return <></>
}
const { switchTheme } = useGlobal()
React.useEffect(() => {
window.addEventListener('scroll', initLive2D)
return () => {
window.removeEventListener('scroll', initLive2D)
}
}, [])
function handleClick() {
if (BLOG.WIDGET_PET_SWITCH_THEME) {
switchTheme()
}
}
useEffect(() => {
window.addEventListener('scroll', initLive2D)
return () => {
window.removeEventListener('scroll', initLive2D)
}
}, [])
if (!BLOG.WIDGET_PET || !JSON.parse(BLOG.WIDGET_PET)) {
return <></>
}
return <canvas id="live2d" className='cursor-pointer' width="280" height="250" onClick={handleClick} alt='切换主题' title='切换主题' />
}