Fix: jotai storage initial value

This commit is contained in:
Dreamacro 2023-02-28 11:57:54 +08:00
parent 15fb59681f
commit 0f141b679c

View File

@ -19,12 +19,16 @@ const clashxConfigAtom = atom(async () => {
}
})
// jotai v2 use initialValue first avoid hydration warning, but we don't want that
const hostsStorageOrigin = localStorage.getItem('externalControllers') ?? '[]'
const hostSelectIdxStorageOrigin = localStorage.getItem('externalControllerIndex') ?? '0'
export const hostsStorageAtom = atomWithStorage<Array<{
hostname: string
port: string
secret: string
}>>('externalControllers', [])
export const hostSelectIdxStorageAtom = atomWithStorage<number>('externalControllerIndex', 0)
}>>('externalControllers', JSON.parse(hostsStorageOrigin))
export const hostSelectIdxStorageAtom = atomWithStorage<number>('externalControllerIndex', parseInt(hostSelectIdxStorageOrigin))
export function useAPIInfo () {
const clashx = useAtomValue(clashxConfigAtom)