相关疑难解决方法(0)

我可以从java层访问存储在React Native的AsyncStorage中的数据吗?

我在React Native中使用了少量用户首选项AsyncStorage.现在,我需要从后台服务中获取这些偏好.我无法AsyncStorage从Java层访问.有办法吗?

在iOS中,我们可以导入RCTAsyncLocalStorage.h和调用_getValueForKey.但是,我无法找到在Android中执行此操作的方法.

java android react-native

7
推荐指数
2
解决办法
2418
查看次数

如何在Android上正确阅读AsyncStorage

似乎可以AsyncStorage从Android(本机)访问;但我仍在努力使这项工作。

在我的React Native应用程序中,我有类似以下内容:

商店

const config = {
  ...
}

export const reducers = {
  ...
  user: user
}


let rootReducer = combineReducers(reducers)
let reducer = persistReducer(config, rootReducer)
Run Code Online (Sandbox Code Playgroud)

用户减速器

export class Actions {
    ...
}

const initialState = {
      first_name: : null,
      last_name: : null,
      email: null,
      addresses: [
          { ... }
      ]
    }
  }
}

export const reducer = (state = initialState, action) => {
  switch (action.type) {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)

从商店获取用户

const user = store.getState().user
console.log(user.first_name) …
Run Code Online (Sandbox Code Playgroud)

android react-native redux asyncstorage redux-persist

2
推荐指数
1
解决办法
2130
查看次数