Skip to content

How to switch from LocalStorage to SessionStorage for atomWithStorage #1220

Closed Answered by dai-shi
meotimdihia asked this question in Q&A
Discussion options

You must be logged in to vote
import { atomWithStorage, createJSONStorage } from 'jotai/utils'

const storage = createJSONStorage(() => sessionStorage)
const someAtom = atomWithStorage('some-key', someInitialValue, storage)

Yeah, we should have this in docs. #805

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TwistedMinda
# for free to join this conversation on GitHub. Already have an account? # to comment
Category
Q&A
Labels
None yet
2 participants