Skip to content

Atom getter/initial value called again with Jotai Scope #2412

Answered by dai-shi
sndrrth asked this question in General
Discussion options

You must be logged in to vote

I'd say it's a designed behavior.
Though, it's unfortunate our API doesn't cover some cases like lazy initialization for primitive atoms and eager initialization for read-only atoms. It's a design limitation. (We might add some new api to cover those, but they are mostly rare cases.)

I'm not 100% sure if I understand your problem with jotai-scope, but I think the following is a workaround.

const now = Date.now();
const foo = atom(() => now);

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sndrrth
Comment options

Answer selected by sndrrth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants