我在React Native中使用了少量用户首选项AsyncStorage.现在,我需要从后台服务中获取这些偏好.我无法AsyncStorage从Java层访问.有办法吗?
在iOS中,我们可以导入RCTAsyncLocalStorage.h和调用_getValueForKey.但是,我无法找到在Android中执行此操作的方法.
似乎可以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)