Await storage setItem in persist middleware #287
-
setItem call in persist middleware is not await-ed. But some storage may do the setItem asynchronously. Code from middleware.ts const setItem = async () => {
const state = { ...get() }
if (whitelist) {
Object.keys(state).forEach((key) => {
!whitelist.includes(key) && delete state[key]
})
}
if (blacklist) {
blacklist.forEach((key) => delete state[key])
}
storage?.setItem(name, await serialize({ state, version }))
} Is it intentional? If it is then how to catch error in case an exception is thrown when calling setItem? |
Beta Was this translation helpful? Give feedback.
Answered by
AnatoleLucet
Jan 28, 2021
Replies: 1 comment 6 replies
-
I don't see why we'd need to await |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
sumartoyo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't see why we'd need to await
setItem
nor catch an error related to it. Can you give an example?