Search code examples
expo-web

How can I use sessionStorage in web browser on expo


I want to use sessionStorage on expo-web development.

How do I access browser based storage with expo?


Solution

  • You can simply access it as you would in a regular JavaScript project.

    sessionStorage.setItem('foo', 'bar');
    

    Do note, however, that if you want this code to run both on Web and Native, you will need to make sure sessionStorage exists before using it.

    const getStoredItem = (key) => window && window.sessionStorage && sessionStorage.getItem(key)
    

    This is required because your Expo app will not have a sessionStorage API once compiled to a native app.