我正在尝试将使用AsyncStorage保存的阵列加载回状态,但似乎无法正常工作。我将数组从AsyncStorage传递回上下文,并调用load_state情况。
function loadList() {
try {
const data = AsyncStorage.getItem('data')
console.log(data)
loadState(JSON.parse(data))
}
catch (error) {
console.log(error)
}
}
const loadState = dispatch => {
return (value) => {
dispatch({ type: 'load_state', payload: value})
}}
case 'load_state':
console.log(action.payload.value)
return [...state, ...action.payload.value]