Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR]: 倒计时组件更新频率过快 #2743

Open
Topgt opened this issue Nov 12, 2024 · 0 comments
Open

[FR]: 倒计时组件更新频率过快 #2743

Topgt opened this issue Nov 12, 2024 · 0 comments

Comments

@Topgt
Copy link

Topgt commented Nov 12, 2024

这个功能解决了什么问题?

如果我的页面有很多很多的倒计时组件,onUpdate 的触发频率太高,但往往我只需要一秒才触发一次,如此高的触发频率,加上我页面有很多的倒计时组件,这对我的页面性能有非常大的挑战。当有50个左右的倒计时组件,页面往往就很卡了。一下是我的代码片段
`
import { View, Text } from '@tarojs/components'
import { CountDown } from '@nutui/nutui-react-taro'
import { useCallback, useState, useTransition } from 'react'

export default function CustomCountdown(p: {
endTime: number
onEnd?: () => void
}) {

const [isPending, startTransition] = useTransition();
const [restTime, setRestTime] = useState({
d: 0,
h: 0,
m: 0,
s: 0
})
const onUpdate = useCallback((time) => {
console.log(time)
startTransition(() => setRestTime(time))
}, [])
return (


{restTime.d > 0
? {restTime.d}天
: 距结束
}
<View className='w-[24px] h-[24px] text-center leading-[24px] rounded-[6px]' style={{ backgroundColor: 'var(--nutui-color-primary)' }}>{restTime.h < 10 ? 0${restTime.h} : restTime.h}
:
<View className='w-[24px] h-[24px] text-center leading-[24px] rounded-[6px]' style={{ backgroundColor: 'var(--nutui-color-primary)' }}>{restTime.m < 10 ? 0${restTime.m} : restTime.m}
:
<View className='w-[24px] h-[24px] text-center leading-[24px] rounded-[6px]' style={{ backgroundColor: 'var(--nutui-color-primary)' }}>{restTime.s < 10 ? 0${restTime.s} : restTime.s}


)
}
`

你期望的组件设计是怎样的?

  • 希望我能自己控制onUpdate 回调的触发频率,我可以自己在onUpdate判断时间然后更新我的state但我还是希望组件能提供这个配置项
  • 页面所有的倒计时组件共用一个state,能统一更新state,现在每个组件有自己的stae,且onUpdate触发频繁,容易导致js主线程阻塞
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant