mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
* Nesting Fixture * Add README to nesting fixture * Apply suggestions from code review Co-authored-by: Ricky <rickhanlonii@gmail.com> * Fixes * Add Redux * Use different versions * Use Consumer API * Rename helper * Write docs * Update README.md * Update README.md Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
13 lines
319 B
JavaScript
13 lines
319 B
JavaScript
import {useState, useEffect} from 'react';
|
|
|
|
export default function useTimer() {
|
|
const [value, setValue] = useState(() => new Date());
|
|
useEffect(() => {
|
|
const id = setInterval(() => {
|
|
setValue(new Date());
|
|
}, 1000);
|
|
return () => clearInterval(id);
|
|
}, []);
|
|
return value.toLocaleTimeString();
|
|
}
|