Skip to content

Are there any examples of "alternative solutions" for using SSR with atomWithStorage? #910

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

You must be logged in to vote

There's an undocumented option delayInit in storage.
If we enable it, it will use initialValue for the first render and then re-render with stored value.

import { atomWithStorage, createJSONStorage } from 'jotai/utils'

const storage = createJSONStorage(() => localStorage)
storage.delayInit = true

const const darkModeAtom = atomWithStorage('darkMode', false, storage)

Replies: 1 comment 2 replies

Comment options

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

@dai-shi
Comment options

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