Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

want the app to save the passing screen after a user has passed the test even when the app exits in react native

import AsyncStorage from '@react-native-async-storage/async-storage';

// or whatever
const key = "hasPassed"

export const hasPassed = async () => {
    return AsyncStorage.getItem(key).then(result => result != null ? JSON.parse(result) : undefined).catch(e => console.log(e))    
}

export const setHasPassed = async (newPassed) => {
    return AsyncStorage.setItem(key, JSON.stringify({hasPassed: newPassed})).catch(e => console.log(e))
}
Comment

want the app to save the passing screen after a user has passed the test even when the app exits in react native

// or whatever name it is
const MainScreen = () => {

   const [showpass, setshowpass] = useState();
   
   useEffect(() => {
       const getState = async () => {
           const result = await hasPassed()
           setshowpass(result ? result.hasPassed : false)
       }
       getState()
   }, [])

   // since it is async
   if (showpass === undefined) {
      return null
   }

   return (
      <View style={styles.body}>
        <Modal
           transparent={false}
           visible={showpass}
           animationType='slide'
           hardwareAccelerated 
         >
            <View style={styles.body}>
              <Text style={styles.toptext}>Congratulations!</Text>
              <Text style={styles.toptext}>Worked great in Turkishya!</Text>
              <Text style={styles.topptext}>
                And mastered the skill 'Alphabets'
              </Text>
            </View>
            </Modal>
      <View>
   );
}
Comment

want the app to save the passing screen after a user has passed the test even when the app exits in react native

if(count<5) {
  //  Alert.alert('pass','pass');
  // showing passing screen in the form of a modal
   setHasPassed(true).then(() => setshowpass(true))
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: How do I change this React Navigation v5 code to v6 
Javascript :: npx create-create-app movie-app 
Javascript :: Check if a user joins, leaves, or moves channels discord.js 
Javascript :: react-native installation error with npx react-native 
Javascript :: change useragent cypress test run 
Javascript :: remove symbols from cnpj js 
Javascript :: how to add link during filter and mapping in javascript 
Javascript :: JSON.stringify on Arrays adding numeric keys for each array value 
Javascript :: in express remove page ,sort ,limit and fields from req.query 
Javascript :: How to access POST form fields in Express 
Javascript :: C# Convert Json File to DataTable using Newtonsoft.Json DLL 
Javascript :: react native mirror text 
Javascript :: open div with onClick element position 
Javascript :: iterate over element parent jquery 
Javascript :: "Uncaught (in promise) TypeError: dispatch is not a function" 
Javascript :: short-circuit evaluation , use of || operator 
Javascript :: generate package json for existing project 
Javascript :: Make Floating label TextInput with password show/hide in react native 
Javascript :: change button text dynamically angular 6 
Javascript :: react console logs not working 
Javascript :: Assigning A Property The Return Value Of A Function In Class 
Javascript :: Recursion In A Class Function 
Javascript :: prisma graphql n+1 problem solution 
Javascript :: Control a progress bar for custom video player 
Javascript :: Backbone View El 
Javascript :: Javascript set control state none opposite 
Javascript :: Backbone View Notes 
Javascript :: javascript reducers 
Javascript :: clear console javascript 
Javascript :: electron js execute command line 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =