#Cannot render date on client side.

11 messages · Page 1 of 1 (latest)

spiral heath
#

cannot render date client side (hydration errors)

#

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

spiral heath
#

thanks

spiral heath
gloomy bronze
#
const [toDisplay, setToDisplay] = useState("loading");
useEffect(() => {
  setToDisplay(date.toLocaleTimeString({
            hour: '2-digit',
            minute: '2-digit',
            second: '2-digit'
          }));
}, []);```
spiral heath
#

oh, so i don't gotta load the time instantly, got it

gloomy bronze
#

Yeah

spiral heath