October 2019
Intermediate to advanced
426 pages
11h 49m
English
The useInterval Hook can be used just like setInterval. We are now going to implement a small counter that counts the number of seconds since mounting the component:
import React, { useState } from 'react'import { useInterval } from 'react-hookedup'
export default function UseInterval () { const [ count, setCount ] = useState(0)
useInterval(() => setCount(count + 1), 1000)
return <div>{count} seconds passed</div>}
Alternatively, we could use an Effect ...
Read now
Unlock full access