I am building a todo app where in each todo the user submits, the user is allowed to edit that todo later if he/she wants. I want the todo to be editable only when the todo is tapped twice under 600ms. Failing to find any other solutions to this problem, I stumbled upon the below given solution.
const [tappedOnce, setTappedOnce] = React.useState(false)
const onTap = () => {
if (tappedOnce) {
setEditable(true)
setTimeout(() => todoRef.current.focus())
setTappedOnce(false)
} else setTappedOnce(true)
}
React.useEffect(() => {
const intId = setInterval(() => {
setTappedOnce(false)
}, 600)
return () => clearInterval(intId)
}, [])
In the solution, I am resetting the tappedOnce
state value to false every 600ms. But as you can probably guess, if the user has 50 todos, then I will have 50 concurrent setInterval
processes running at the same time. Is this going to affect the performance of the app by any significant margin? Are there any better solution to this problem?