/
Percival
/
reactJS_course
Обзор
Документация
Войти
/
Percival
/
reactJS_course
Код
Запросы
4
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
task6
task_1_fsd/src/features/refExamples/ClickTimer.tsx
35 строк
896 B
Rituparn
Added the 5th task
26 окт 2025, 19:34
26 окт 2025, 19:34
72790f9
Код
Авторство
О чём код?
import { useRef } from 'react'; interface ClickData { startTime: number | null; clickCount: number; } export const ClickTimer = () => { const clickDataRef = useRef<ClickData>({ startTime: null, clickCount: 0, }); const handleClick = () => { const currentTime = Date.now(); if (clickDataRef.current.startTime === null) { clickDataRef.current.startTime = currentTime; clickDataRef.current.clickCount = 1; console.log('First click recorded'); } else { clickDataRef.current.clickCount += 1; const timeDiff = currentTime - clickDataRef.current.startTime; console.log(`Time since first click: ${timeDiff}ms, Total clicks: ${clickDataRef.current.clickCount}`); } }; return ( <div> <h3>ClickTimer</h3> <button onClick={handleClick}>Click Me</button> <p>Open console to see results</p> </div> ); };