question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

utils - Atom not found

See original GitHub issue

I have a utility component where I create some atoms, and maybe set some values depending on props and other stuff, but I don’t need the values, I export the value getters separately.

So I am using useUpdateAtom in this component instead of useAtom, as I assume it would have some performance benefits.

The problem is always get this error:

[Bug] Atom state not found. Please file an issue with repro: updateAtomState 
{key: 1, init: 1, read: ƒ (), write: ƒ ()}

I tracked this down and it appears there is some setup work to initialize the atom’s state that is done in useAtom, but when using useUpdateAtom, this init is only done on the read only copy of the atom. https://github.com/pmndrs/jotai/blob/072e26a41f590adf6b7e8e8683d48cc3d30caddb/src/utils/useUpdateAtom.ts#L11

In that line, useAtom (and the init contained in it) is run for writeOnlyAtom, but not for anAtom. The init I think is missing is here: https://github.com/pmndrs/jotai/blob/072e26a41f590adf6b7e8e8683d48cc3d30caddb/src/core/useAtom.ts#L66

I have a minimal repro here: https://codesandbox.io/s/jotai-atom-state-not-found-9dm2t just push the button and look at the console =)

BTW, thanks for the library, its great!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jcane86commented, Dec 15, 2020

ah, I see… I thought that might be the case… I will make sure to initialize them before using them. Thank you!

0reactions
dai-shicommented, Dec 15, 2020

Good morning.

I assume it is interpreting my callback as an updater function.

Exactly. It would behave the same with React.useState.

You could change the behavior with a derived atom.

const callbackAtom = atom(() => null)
const derivedCallbackAtom = atom(
  get => get(callbackAtom),
  (_get, set, nextCallback) => set(callbackAtom, nextCallback)
)

Unfortunately both of these approaches give this warning:

Would you create a small repro in codesandbox? Oh, I think I get it. You are probably trying to update an atom that is never used. Currently, an atom must be used explicitly or dependent with other atoms. You can’t update it before the initialization. We discuss about this behavior recently, and hope to make a better documentation, give better warning message or fix it fundamentally if possible.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Atom package manager not working - Stack Overflow
I've tried many ways, removed every atom component again installed but still giving me same error. Fetching featured packages failed.Hide output ...
Read more >
Utils — Jotai, primitive and flexible state management for React
The freezeAtom takes an existing atom and returns a new derived atom. The value with the new derived atom will be frozen (i.e....
Read more >
git-utils by atom - GitHub Pages
Open the repository at the given path. This will return null if the repository at the given path does not exist or cannot...
Read more >
PyMOL Command Reference
The command descriptions found in this file can also be printed to the PyMOL ... DESCRIPTION Unset all object and atom level (not...
Read more >
m4a file, how to fix "moov atom not found Invalid data ... - Reddit
m4a file, how to fix "moov atom not found Invalid data found when processing input" ... Right clicking the file -> utils ->...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found