chore: replace all set interval (#3411)

This commit is contained in:
Joel 2024-04-12 16:02:56 +08:00 • committed by GitHub
commit 4d54637921
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 70 additions and 62 deletions

View file

@ -1,5 +1,6 @@
import { forwardRef, useEffect, useRef } from 'react'
import cn from 'classnames'
import { sleep } from '@/utils'
type IProps = {
placeholder?: string
@ -32,14 +33,13 @@ const AutoHeightTextarea = forwardRef(
return false
}
const focus = () => {
const focus = async () => {
if (!doFocus()) {
let hasFocus = false
const runId = setInterval(() => {
hasFocus = doFocus()
if (hasFocus)
clearInterval(runId)
}, 100)
await sleep(100)
hasFocus = doFocus()
if (!hasFocus)
focus()
}
}