sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.02k stars 268 forks source link

如何同步获取数据? #244

Closed xdlgj closed 4 years ago

xdlgj commented 4 years ago

//用来管理当前登录用户的reducer函数 const initUser = AsyncStorage.getItem(USER_KEY) function user (state = initUser, action) { switch (action.type) { case REVICE_USER: return action.user case RESET_USER: return {} default: return state } }

sunnylqm commented 4 years ago

如果是redux,建议配合redux-persist使用,不用自己操心怎么存取

sunnylqm commented 4 years ago

直接用的话,要么await,要么then,没有别的用法

orzhtml commented 4 years ago

如果没有存数据,let res = await storage.load({ key: 'theme' }) 会报错

sunnylqm commented 4 years ago

@orzhtml 有其他问题可以另外开个issue具体说一下吗?