0

I can find information on how to write calls to AsyncStorage, how it actually stores information on device, etc., and some basic examples of usage storing keys, but what I'm looking for is a broader understanding of why I would use it.

The reason I'm asking is that I've recently had to refactor one area of our (react-native) mobile-app, which was being buggy and - not unrelated! - had become one unfathomable beast. It was previously a huge single class, and in its componentDidMount/unMount had calls to AsyncStorage, where it was stashing some state variables.

(Judging from the comments, at least part of the reason was to do with the previous developer struggling with understanding how to use/access state within FlatList, but I think it's more than just that)

The refactored code achieves the same goals as before, through several separate functional components, each performing a specific task. Everything FlatList calls is now stateless, and, having just finished testing, all the previous functionality seems to have been matched.

But, I realise I haven't used any calls to AsyncStorage, and I'm left wondering if that is a bad thing? I can imagine that I could stash into AsyncStorage all the state from this part of the app such that if it crashed we could jump back to whatever point we got to. And I suppose that might be handy, in its way. But is that a sensible use of async storage? Is that what y'all are using it for? Was the previous use case a poor one and should I move on without it?

(I appreciate this question is a more concept'y than what I normally look for / ask, and if I should be putting it somewhere else, please do say!)

  • AsyncStorage is a reasonable way to store data that you want to be available from launch to launch. There are other solutions that are more robust (such as a database), but it doesn't sound like that's how what you have is being used. – jnpdx Jul 28 '21 at 19:33
  • By "launch-to-launch", do you mean between one App launch and the next? We do, also, use a database (mongo). This part of the app displays a set of tasks. We query our DB to get those tasks, then as the user records data about performing the tasks we send data back to the DB. The AsyncStorage seems to be storing information associated with where-are-we in the list of tasks. – Oliver Browne Jul 28 '21 at 19:45
  • By launch-to-launch, I mean that when an app is killed (by the user or by the system), it loses all state in memory. When it is launched again, it must retrieve that state from somewhere if it wants to use it again. `AsyncStorage` is *a* solution for that. It sounds like what your app is doing is a reasonable use case for this. – jnpdx Jul 28 '21 at 19:47

0 Answers0