It doesn't work when you are using NextJS and try to access to local/session Storage through a custom hook.
The messages is:
Server Error
ReferenceError: sessionStorage is not defined
An example of the custom hook is the following:
const useAccountInitialState = () => {
const [state, setState] = useState({
account: {
details: {}
},
accountStorage: () => ({})
})
const accountStorage: AccountStorage = useCallback((time = STORAGE_EXPIRE_DAYS) => ({
details: JSON.stringify(localStorage.get('details'))
}), [])
const account: () => AccountInitialState = useCallback(() => ({
details: accountStorage().details ?? {details: {}}
}), [])
useEffect(() => {
setState({account, accountStorage})
}, [])
return state
}
I'm using:
- NextJS v13.2.4
- React v18.2.0
It doesn't work when you are using NextJS and try to access to local/session Storage through a custom hook.
The messages is:
An example of the custom hook is the following:
I'm using: