Currently, I am making use of the Mobx Persist Store plugin which allows me to store MobX Store data locally.
Although the documentation does not provide a TypeScript version, I made modifications to 2 lines of code (one in the readStore
function and another in the writeStore
function, which can be compared at https://github.com/quarrant/mobx-persist-store#with-mobx-6) to address TypeScript errors. However, this led to a new error:
import {
persistence,
useClear,
useDisposers,
isSynchronized,
StorageAdapter,
} from 'mobx-persist-store'
import { FrameItStore } from '@/store/index'
function readStore(name: string) {
return new Promise<string>((resolve) => {
const data = localStorage.getItem(name) || '{}'
resolve(JSON.parse(data))
})
}
function writeStore(name: string, content: string) {
return new Promise<Error | undefined>((resolve) => {
localStorage.setItem(name, JSON.stringify(content))
resolve(null)
})
}
export default persistence({
name: 'FrameItStore',
properties: ['counter'],
adapter: new StorageAdapter({
read: readStore,
write: writeStore,
}),
reactionOptions: {
// optional
delay: 2000,
},
})(new FrameItStore())
An error is occurring with the null
value in resolve(null)
within the writeStore
function.
The error message is as follows:
Argument of type 'null' is not assignable to parameter of type 'Error | PromiseLike<Error | undefined> | undefined'.ts(2345)
Any suggestions on how to resolve this issue?