Display a screen only once in react native

472 Views Asked by At

I have a screen made with react-native-swiper where I give an introduction on how the app works, but I would like to display this screen only the first time the user opens the app.

how can I do this?

1

There are 1 best solutions below

0
On

you can store a bool value in a local storage, even in the secured store by using the expo SecureStore package. Then check the store for that value when the app starts.

import * as SecureStore from 'expo-secure-store';

const app = ()=>{
    useEffect(()=>{
       const getStoredValue = async ()=> {
         const introduction = await SecureStore.getItemAsync("introduction");
         //use this variable to determine if you want to run the introduction.
 
         //if introduction doesn't exist in the secure store create one 
         if (introduction === null ) {
             try {
                  SecureStore.setItemAsync("Introduction", true);
                 }
             catch (ex) {}
       }
       getStoredValue();
    },[]);
}