medium10 pts · first answer countsreact-nativereact-hooks
Timer counter stuck at one
What does this component show after about 5 seconds?
function Timer() {
const [count, setCount] = useState(0)
useEffect(() => {
const id = setInterval(() => setCount(count + 1), 1000)
return () => clearInterval(id)
}, [])
return <Text>{count}</Text>
}Discussion 0
Join free to post in the discussion.
Related questions
- Why list items need keysMobile App Developer
- Calling setCount twiceMobile App Developer
- React Native New ArchitectureMobile App Developer
- Listener without effect cleanupMobile App Developer
- Animation stutters while JS is busyMobile App Developer
- Memoized rows still re-renderMobile App Developer
- Stale value in useEffectFrontend Developer
- Ref value not shown on screenFrontend Developer