English 中文(简体)
Async Storage can t retrive data
原标题:

I m currently creating an app using react native and async storage, but there s a problem when I add the new data, it can t show it on the screen until I ctrl+s the code file, but I want that when I add the new data and go back to the screen, it must show on it. I m new with this so if you know the problem or solutions please help me, thank u in advance.

  const [data, setData] = useState();

  const getData = async () => {
    try {
      keys = await AsyncStorage.getAllKeys();
      data1 = await AsyncStorage.multiGet(keys);
      obj = Object.fromEntries(data1);
      Object.keys(obj).forEach(key => {
        obj[key] = JSON.parse(obj[key]);
        data2.push(obj[key]);
      });
      setData(data2);
      console.log( DATA:  + data2);
      return data;
    } catch (error) {
      console.log( Err:  , error);
    }
  };
  useEffect(() => {
    getData();
  }, []);
问题回答

暂无回答




相关问题
Async Storage can t retrive data

I m currently creating an app using react native and async storage, but there s a problem when I add the new data, it can t show it on the screen until I ctrl+s the code file, but I want that when I ...

React JS How to submit a form and THEN navigate to new page?

I want to preface this by saying I am completely brand new to web development and am trying to add features to legacy code (and honestly I am not sure what the entire tech stack is)! Thank you for any ...

React Hook Form Error on custom Input component

I am having a problem when I use react hook form + zod in my application, in short the inputs never change value and I get the following error in the console: Warning: Function components cannot be ...

HandleClick not being recognized as a prop

I m trying to get my menu to show when I click the sidebar, but I m getting an error "react-dom.development.js:86 Warning: React does not recognize the handleClick prop on a DOM " import { ...

Is there an equivalent to localStorage in React Native?

I d like to implement the equivalent to the javascript localStorage in my React Native app. But I m unsure how to set. To function how I want it to, I would like the localStorage to be stored every ...

热门标签