useTimeout()
2022年5月1日小于 1 分钟
useTimeout()
Question
Create a hook to easily use setTimeout(callback, delay)
.
- reset the timer if delay changes
- DO NOT reset the timer if only callback changes
Code
export function useTimeout(callback: () => void, delay: number) {
// your code here
}
// if you want to try your code on the right panel
// remember to export App() component like below
// export function App() {
// return <div>your app</div>
// }