Search code examples
reactjsreact-nativeasyncstorage

Why does AsyncStorage takes long time to load the data?


I am creating a simple calculator application in react native, and I am using AsyncStorage for storing results, but it takes too long to get the data from AsyncStorage.


Solution

  • Solution 1:

    If you want to get the data instantly then you can store the data in a store provider like Redux and you can store it in your async storage so you can reach them back if the app closed.

    saveDataAction: (payload) => dispatch(saveDataAction(payload))
    

    Solution 2

    If you don't care about using the data in multiple pages then you can use useState to store data and get it instantly.

    const [data, setData] = useState([]);
    
    
    
    const getData = () => {
       fetch(url).then(data => setData(data));
    }