undefined is not a function (near '...state.map...')

Viewed 103

When I load todos from storage, I get this error. When I replace the loadDate() function with [] this error is not present, but then I cannot get the saved todos from the phone storage. Help me please.The problem may be related to the wrong procedure. I had this before I used useReduce()

const saveData = async () => {
    await SecureStore.setItemAsync(STORAGE_KEY, JSON.stringify(state))
}
const loadData = async () => {
    try {
        const load = JSON.parse(await SecureStore.getItemAsync(STORAGE_KEY) || JSON.stringify([]))
        if (load != null) {
            return load
        }
    } catch (e) {
        alert (e)
    } 
}

const [ state, dispatch ] = useReducer(reducer, loadData())

useEffect(() => {
    saveData()
}, [state])
0 Answers
Related