/
lizardking
/
react_project
Обзор
Документация
Войти
/
lizardking
/
react_project
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/features/refExample/model/useClickTimer.ts
19 строк
505 B
LizardKing
Task 5 - useRef
17 окт 2025, 03:34
17 окт 2025, 03:34
e989e42
Код
Авторство
О чём код?
import { useRef } from 'react' import type { ClickData } from './types' export function useClickTimer() { const ref = useRef<ClickData>({ startTime: null, clickCount: 0 }) const handleClick = () => { const now = Date.now() ref.current.startTime ??= now ref.current.clickCount += 1 const diff = now - (ref.current.startTime ?? now) // eslint-disable-next-line no-console console.log(`ClickTimer: +${diff}ms, total=${ref.current.clickCount}`) } return { handleClick } }