Skip to content

Persistent data with Jotai #350

Closed Answered by Aslemammad
ghost asked this question in Q&A
Mar 11, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Hello @grubeli, You can check this.

const strAtom = atom(localStorage.getItem('myKey') ?? 'foo')

const strAtomWithPersistence = atom(
  (get) => get(strAtom),
  (get, set, newStr) => {
    set(strAtom, newStr)
    localStorage.setItem('myKey', newStr)
  }
)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ghost
Comment options

@Aslemammad
Comment options

Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant