DEV Community

Discussion on: useContext() with Typescript

Collapse
 
enough7 profile image
Enough7 • Edited

You can use localstorage for this:

const USER_ID_KEY: string = "userId";
export let thisUser: IUser = {
    id: parseInt(localStorage.getItem(USER_ID_KEY) || '-1') 
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
madv profile image
Amateur blogger

Thank you for the alternative, however what if the user has disabled his localStorage? ;)

Thread Thread
 
enough7 profile image
Enough7

I did not know you can disable it

Some comments have been hidden by the post's author - find out more