Is AsyncStorage shared across apps? - react-native

My question originates from the docs: https://facebook.github.io/react-native/docs/asyncstorage.html#clear
AsyncStorage.clear -> Erases all AsyncStorage for all clients, libraries, etc....
does that mean that all apps share the same AsyncStorage?

AsyncStorage is not shared between multiple apps. Every app runs it it's own sandbox environment and has no access to other apps.
To call AsyncStorage.clear only means you will delete all data which your app has stored in AsyncStorage.
That includes
all data which was stored by a library that uses AsyncStorage like
https://github.com/sunnylqm/react-native-storage
all data from all users (in case of multi user)
For more information about app sandboxing you can read this answer:
What is Sandbox in ios , Can i Trans data between in one App to Another App in iPhone,if possible how

Related

How to sync an ionic vue app with Google's Firestore?

I want to build an app where users can jointly work on lists. The app should be avialable offline and sync changes when it goes online again.
For the app iteself, I've decided to go with Ionic Vue. For storage, I created a Firestore and was able to sync between my app and Firestore by using the Firesotre method onSnapshot() (doc). Although this working at the moment, the resulting code does not look very elegant and I have to create multiple very similar Firebase calls in different components. This slows the app down and (I think) also prevents me from making the lists available offline and sync them again when there is a connection.
I recently discovered vuex and the idea sounds quite fitting for my case: I store all app data in the vuex store and sync it (both ways) to Firestore. My components access the vuex store instead of the Firestore directly. Here are some questions regarding this idea:
Is this in general how the vuex store and Firestore are supposed to be used?
Can I make the vuex store data available on my phone and only sync it to the Firestore whenever there is a connection (to make the app available offline inlc. modifying data)?
If so, what is the easiest way to sync the vuex store to Firestore?
Regarding the syncing: I found Vuexfire, but it does not really work for me as expected - I guess this is because it is built on Vue 2 (as against Ionic which is built on Vue 3). I also found Vuex Easy Firestore, but I'm a bit reluctant to try new tools, as Vuexfire cost me several hours.
Thanks for reviewing my implementation ideas!

How to store local private user data with React Native app?

I'm about to start working on a expense tracker app for mobile and I would like to use React Native with Expo (pretty new to mobile techs). Maybe I will share it with some friends or other people and the question that cames up is where to store their data (in this case is sensitive as they will register their money's movement).
What I mean is, I could use any cloud DB (Mongo, Firestore, etc) but I will have access to everything they register there and I wouldn't like that, just for security and their privacy sake.
So, is there a way to store their data or everything they register locally in their phones? So the app can only access to the data that is stored there and I can't see it. Or any other possibility?
I found the AsyncStorage API but I don't know if this is the correct approach for what I'm looking for. I didn't code anything yet as I don't know which would be the right path.
You can use Secure Store since you're using expo.
expo-secure-store provides a way to encrypt and securely store key–value pairs locally on the device. Each Expo project has a separate storage system and has no access to the storage of other Expo projects.
See https://docs.expo.dev/versions/latest/sdk/securestore/
I had a similar case and i went for realm.js .

Offline first React Native Expo app with background sync

I am looking at building an offline first React Native Expo app that automatically pushes data to an API when the device gets a connection. However I am struggling to see how if this is possible within Expo and need some guidance.
The app will need to store data from an API for offline use (presumably on first load, which will then be used to populate fields in a form). The form needs to work offline, with the input data stored on the device until it receives a new connection. At that point the app should push the data to an API (whilst the app is in the background). So I need to do multiple things:
Automatically download and store data from an API on first launch.
Store input data - from form fields whilst offline.
Background sync - Upload this user form data when a new connection is received, regardless of whether the app is running in the background or not.
Work on Android and iOS devices.
I have been looking at redux-offline, but unsure if it still supported and/or will satisfy all four requirements?
There is also redux-persist but I can't see how this satisfies the background sync?
Thanks for any help/guidance!
From my point of view, redux-persist is less opinionated compared to redux-offline. I pick redux-persist with useNetInfo hook to listen to network availability.
1. Automatically download and store data from an API on first launch.
When app launch, query initial data and dispatch to redux store and synced automatically to local storage by redux-persist
2. Store input data - from form fields whilst offline.
With useNetInfo, the app can detect network connectivity status, when not connected, dispatch to the redux store with a flag to indicate offline unsynched data.
You need to write a network connectivity listener which is executed when the network state changes and continuously track unsynched data and sync with the database when available and purge those temporary data like form values.
3. Background app sync
Expo SDK provides API https://docs.expo.dev/versions/latest/sdk/background-fetch/
to run continuously a background task at a certain time threshold.
You can sync offline data when the network returns back while the app is background.
Disclaimer: Background tasks run outside of React componentS tree. You can't access redux store data through the react-redux's store component or hooks based API.
redux-persist saves data with Async Storage and you need to directly access data as below.
AsyncStorage.getItem("persist:[REDUCER_CONTAIN_INTERESTED_DATA]")
This seems to be an issue with server state with a client cache. Looks like an ideal case for react-query to solve.
Automatically download and store data from an API on first launch.
This should be taken care of by query prefetching
Store input data - from form fields whilst offline.
Probably needs client state(redux/Zustand etc) for managing state with unverified fields. For storing submitted forms, react-query supports offline caching of 'mutations'.
Background sync - Upload this user form data when a new connection is received, regardless of whether the app is running in the background or not.
Work on Android and iOS devices.
See above.

{React native}, Offline mobile app , sotore data in user device

I am new to react-native and currently aiming to make a simple ios application using react-native.
The developing application basically stores pre-installed 100 types of text files and other 100 types of text data that users can personally add after installation.
My question is that should 'react-native-SQLite-storage' be used to store data on a user's mobile app?
I have done some research and figured out two ways to store data, one is to use Async Storage, another one is to use react-native-SQLite-storage, and still confusing the difference between those ways.
I appreciate some ideas from people who have been developed react native app before.
Thanks.

React native already has Async Storage. Why should I use Redux and Redux Thunk in my react native app?

I have a stupid question but I'm super confused from it. If React Native has Async Storage available, why should one use Redux and Redux Thunk? Why can't we just save all the data in the Async Storage? What is the purpose/benefit of using Redux over Async Storage?
They are different things and serve different purposes.
Async Storage is a simple key/value store. It only works with strings. So you can do, AsyncStorage.set("someKey", "someValue") That's all it does. It's purpose is to save/persist data on the file system of the phone so that it can be used over multiple app sessions (closing and opening the app)
Redux is a full state management solution that allows you to keep any kind of javascript data in memory during the running of the app and have it available anywhere in the app. Think about how in a react-native app two different components cannot easily see and modify each others state, there has to be some way for them to communicate. Basically, Redux helps you do this.
Considering your level of understanding, I would recommend looking into React Context before you tackle Redux. It is a significantly simpler state management solution than Redux. It is included with React/doesn't require a different code structure and will also help you understand the purpose of Redux.
Redux and Async Storage is 2 different concept. To be clear, Redux is the state management and Async storage is like an client database. If you are familiar web development, I can say that Redux is like session storage and async storage is local storage.
It means that Redux is storing the state of app at the time you using it, when the app is killed, all the state in Redux will be deleted. In contrast, async storage store the app' state even if the app is killed.
Therefore, there are a combination of this two. Example: When user first time login to the app, we will store the user info in the async storage so from the next time, user will not be required to login again.