Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAtom(undefined) throws Invalid value used as weak map key #2776

Closed
kevinschaich opened this issue Oct 19, 2024 · 1 comment
Closed

useAtom(undefined) throws Invalid value used as weak map key #2776

kevinschaich opened this issue Oct 19, 2024 · 1 comment

Comments

@kevinschaich
Copy link
Contributor

This should be checked for or caught and re-thrown as a more helpful error message.

To Repro:

const value = useAtom(undefined)

    -> TypeError: Invalid value used as weak map key

I hit this today and if it weren't for this comment I would have been very struggling for a few hours:
#1816 (reply in thread)

One potentially common way people might hit this is if they use nested/split atoms and try to reference a key that doesn't exist.

e.g. objects:

const objectAtom = atom({
    a: atom(...)
    b: atom(...)
)

...

const bValue = useAtomValue(useAtomValue(objectAtom)[c])

e.g. lists:

const listAtom = atom([atom(...), atom(...)]

...

const thirdValue = useAtomValue(useAtomValue(listAtom)[2])

Related: #2272, #1817, #1177, #1816, #2239, #2273

@kevinschaich
Copy link
Contributor Author

cc: @dai-shi I believe you replied to a few of the issues/discussions above.

@pmndrs pmndrs locked and limited conversation to collaborators Oct 19, 2024
@dai-shi dai-shi converted this issue into discussion #2777 Oct 19, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant