It seems that it's possible access the AsyncStorage
from Android (native); but I still struggling to make this work.
In my React Native application, I have something like:
Store
const config = {
...
}
export const reducers = {
...
user: user
}
let rootReducer = combineReducers(reducers)
let reducer = persistReducer(config, rootReducer)
User Reducer
export class Actions {
...
}
const initialState = {
first_name: : null,
last_name: : null,
email: null,
addresses: [
{ ... }
]
}
}
}
export const reducer = (state = initialState, action) => {
switch (action.type) {
...
}
}
Getting the User from store
const user = store.getState().user
console.log(user.first_name) // Steve
...
Now the issue starts when I try to get the same user from Android, of all my frustrated attempts this is what I have:
try {
readableDatabase = ReactDatabaseSupplier.getInstance(getReactApplicationContext()).getReadableDatabase();
catalystLocalStorage = readableDatabase.query("catalystLocalStorage", new String[]{"value"}, "key = ?", new String[] { "full_name" }, null, null, null);
String[] names = catalystLocalStorage.getColumnNames();
if (catalystLocalStorage.moveToFirst()) {
final String value = catalystLocalStorage.getString(catalystLocalStorage.getColumnIndex("value"));
Log.d(TAG, value);
}
} finally {
if (catalystLocalStorage != null) {
catalystLocalStorage.close();
}
if (readableDatabase != null) {
readableDatabase.close();
}
}
Since the User it's an object, I don't know if this is the right way to get the 'first_name'
, I tried get 'user'
but didn't worked.
I'm starting to think that I should use react-native-sqlite-storage where I would know my data structure, but I don't know if I would be able to access that database on Android.
PS: I want access AsyncStorage
not SharedPreferences
Lib Versions
react-native: 0.48.4
redux: 3.7.2
redux-persist: 5.4.0
Some questions that didn't work
See Question&Answers more detail:
os