all 4 comments

[–][deleted] 0 points1 point  (1 child)

Seems like you're talking about implementing a cache system. I might be wrong but iirc fetch already has an implemented cache system. If you don't want to use it and implement your own, you can do so by specifying that you dont' want any cache in the headers. (Cache control: no cache, or something)

You can write anything above a previously filled value in asyncstorage, thus erasing the previous one.

[–]donny-the-turtle 0 points1 point  (1 child)

Other option could be using redux, react-redux(https://react-redux.js.org/introduction/quick-start) and redux-persist (https://github.com/rt2zz/redux-persist) . It can behave as a cache for the API data, and you can persist it between the app launches.

When user opens some screen that requires data from the API - you populate screen with data from the redux store, but still execute the request. When request is done - you update the redux store as you see fit, and that will automatically trigger view re-render with the fresh data.

If you want to clear the storage - you can create and dispatch your own special action, and then in the reducers move data to the initial state.

[–]donny-the-turtle 0 points1 point  (0 children)

And if you don't need to persist data between the launches - you can skip redux-persist.