document 非空判断

This commit is contained in:
tangly1024
2022-04-26 12:50:35 +08:00
parent 0b65e240bc
commit 1a7efd80ac
10 changed files with 15 additions and 15 deletions

View File

@@ -11,23 +11,23 @@ export const LayoutSearch = (props) => {
const { keyword } = props
useEffect(() => {
setTimeout(() => {
const container = document.getElementById('container')
const container = typeof document !== 'undefined' && document.getElementById('container')
if (container && container.innerHTML) {
const re = new RegExp(`${keyword}`, 'gim')
container.innerHTML = container.innerHTML.replace(re, `<span class='text-red-500 border-b border-dashed'>${keyword}</span>`)
}
},
100)
100)
})
return <LayoutBase {...props}>
<div className='py-12'>
<div className='pb-4 w-full'>{locale.NAV.SEARCH}</div>
<SearchInput currentSearch={keyword} {...props}/>
<TagGroups {...props}/>
<CategoryGroup {...props}/>
<SearchInput currentSearch={keyword} {...props} />
<TagGroups {...props} />
<CategoryGroup {...props} />
</div>
<div id='container'>
<BlogPostListScroll {...props}/>
<BlogPostListScroll {...props} />
</div>
</LayoutBase>
}

View File

@@ -9,7 +9,7 @@ const Progress = ({ targetRef, showPercent = true }) => {
const currentRef = targetRef?.current || targetRef
const [percent, changePercent] = useState(0)
const scrollListener = () => {
const target = currentRef || document.getElementById('container')
const target = currentRef || (typeof document !== 'undefined' && document.getElementById('container'))
if (target) {
const clientHeight = target.clientHeight
const scrollY = window.pageYOffset