#Cannot render date on client side.
11 messages · Page 1 of 1 (latest)
so i'm making a real time ish clock, ```js
const [date, setDate] = useState(new Date());
useEffect(() => {
setInterval(() => setDate(new Date()), 1000);
}, []);
```js
{date.toLocaleTimeString({
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
})}
but this just ends up throwing hydration errors
Wrap it in a useEffect
just realised I could've just call toLocaleTimeString inside useEffect
thanks
well that doesn't work either
const [toDisplay, setToDisplay] = useState("loading");
useEffect(() => {
setToDisplay(date.toLocaleTimeString({
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
}));
}, []);```
oh, so i don't gotta load the time instantly, got it
Yeah
ay that worked, thanks