Open
Description
I have the following setup
export type LastLocation = {
location: null|[number, number]
state: "DENIED"|"ALLOWED"|"UNKNOWN"|"ASKED"
}
export const lastLocation = persisted<LastLocation>({
location: null,
state: "UNKNOWN",
}, "last-location", {
storageType: "LOCAL_STORAGE",
})
which I then use in my component
<script lang="ts">
import {lastLocation} from "./utils"
if($lastLocation.state === "UNKNOWN") {
// error
}
</script>
The problem is, that the first time the store is initialized and saved to the local storage with it's default value, $lastLocation
is undefined. I need to reload the store/page.
This line is the culprit https://github.com/square/svelte-store/blob/main/src/persisted/index.ts#L140
The initial value should be passed, NOT undefined
Metadata
Metadata
Assignees
Labels
No labels