chore: replace all set interval (#3411)
This commit is contained in:
parent
64e395d6cf
commit
4d54637921
4 changed files with 70 additions and 62 deletions
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue