chore: replace all set interval (#3411)

This commit is contained in:
Joel
2024-04-12 16:02:56 +08:00
committed by GitHub
parent 64e395d6cf
commit 4d54637921
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()
}
}