my project is on nextjs. before return, I need localStorage or window. but it gives me the Error localStorage is not defined and window is not defined... I have checked other questions but there is no proper answer. Please someone can help me to fixes this issue. Here is code:
import moment from "moment";
import { useState } from "react";
export default function Clicked() {
const [passed, setPassed] = useState(false)
const click = () => {
const currentTime =moment().format('HH:mm:ss');
var endTime = moment().add(10, 'second').format('hh:mm:ss A')
localStorage.setItem('currentTime', currentTime)
localStorage.setItem('endTime', endTime)
console.log(endTime)
console.log(currentTime)
}
console.log(window)
const currentTime = localStorage.getItem("currentTime");
console.log('currentTime', currentTime)
return(
<>
<button onClick={() => click()}>click</button>
<h1>hello</h1>
</>
)
}