首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >希望应用程序根据每个用户在react本机中分别保存状态。

希望应用程序根据每个用户在react本机中分别保存状态。
EN

Stack Overflow用户
提问于 2022-05-14 08:35:28
回答 1查看 54关注 0票数 0

我有一个进行测试的应用程序,当当前登录的用户通过测试时,应用程序会显示一个模式,告诉他他已经通过了测试。我希望应用程序为这个特定的用户保存这个状态,这个用户目前正在登录,即使他关闭了应用程序,传递的屏幕仍然在那里,但是现在如果一个全新的用户登录,应用程序应该从一开始就重新开始,它应该首先显示测试屏幕,然后如果用户通过测试,应用程序就会相应地为他保存状态。

长话短说,我希望我的应用程序根据每个用户的情况分别为他们保存状态(他们是否通过了测试)。我想要一个明确而简单的解决办法。下面是我的test.js的代码片段:

代码语言:javascript
复制
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
)
}
EN

回答 1

Stack Overflow用户

发布于 2022-05-14 16:40:49

有多种方法可以解决这个问题。您可以使用AsyncStorage或使用反应-还原保留-持久化构建更复杂的逻辑。

总之,您只需缓存用户详细信息/数据,您就可以按照我的上述建议进行缓存。(我的答案不需要代码片段)

谢谢。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72238572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档