我有一个进行测试的应用程序,当当前登录的用户通过测试时,应用程序会显示一个模式,告诉他他已经通过了测试。我希望应用程序为这个特定的用户保存这个状态,这个用户目前正在登录,即使他关闭了应用程序,传递的屏幕仍然在那里,但是现在如果一个全新的用户登录,应用程序应该从一开始就重新开始,它应该首先显示测试屏幕,然后如果用户通过测试,应用程序就会相应地为他保存状态。
长话短说,我希望我的应用程序根据每个用户的情况分别为他们保存状态(他们是否通过了测试)。我想要一个明确而简单的解决办法。下面是我的test.js的代码片段:
import React ,{useState, useEffect} from "react";
import {View, Alert, Image, StyleSheet, Text, Modal, TouchableOpacity, TouchableHighlight} from 'react-native';
import Voice from 'react-native-voice';
import auth from '@react-native-firebase/auth';
export default alpht =({navigation}) => {
function Check() {
if (results.includes(words[index])){
Alert.alert('Correct!','You are learning so well!');
if(index==7) {
if(count<=5)
{
//displaying the modal for passing screen
setshowpass(true);
}
else{
console.log(count)
Alert.alert('fail','fail');
}
}
if (index==7){
setndis(true);
setdis(true);
setidis(true);
}
else{
setndis(false);
setdis(true);
setidis(true);
}
}
else{
Alert.alert('Ops!','Looks like you went wrong somewhere. Try again!');
setcount(count+1);
setdis(true);
setndis(true);
if(count==5){
Alert.alert('Restest', 'Looks like you had way too many mistakes!')
setind(0);
setcount(0);
setdis(true);
}
}
}
const words=['ceket', 'çilek', 'elma', 'fare', 'öğretmen', 'otobüs', 'şemsiye', 'uçak'];
const [show, setshow]=useState('');
const [showpass, setshowpass]=useState(false);
useEffect(() => {
setshow(true);
}, []);
return (
..other code here
)
}发布于 2022-05-14 16:40:49
有多种方法可以解决这个问题。您可以使用AsyncStorage或使用反应-还原和保留-持久化构建更复杂的逻辑。
总之,您只需缓存用户详细信息/数据,您就可以按照我的上述建议进行缓存。(我的答案不需要代码片段)
谢谢。
https://stackoverflow.com/questions/72238572
复制相似问题