-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
Throw error on useAtom(undefined)
or useAtom(null)
#2778
Throw error on useAtom(undefined)
or useAtom(null)
#2778
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening up a PR.
Here are some suggestions.
Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
Nice, I like the second one @dai-shi. Simple and won't break apps in production. |
Preview in LiveCodesLatest commit: fceda43
See documentations for usage instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change.
I reviewed it again, and now wonder if this check should be in store.ts
, because the issue isn't specific to hooks.
@dai-shi would that error get thrown in the place we expect / where we are hitting the bug now if we move it? If that's the preferred path forward I'd need more guidance on where specifically you'd like the check implemented |
I added two commits illustrating two ideas. Do they work as expected? |
@kevinschaich whenever you have time. |
Hey @dai-shi, changes working as expected for me. I think this is OK to move forward with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. Will merge it later.
* Fix undefined or null atoms * Simplify conditional, only in dev mode Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> * Update useSetAtom.ts * move warning to store.ts * move the warning in getAtomState --------- Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com> Co-authored-by: daishi <daishi@axlight.com>
Related Bug Reports or Discussions
Fixes #2777
Summary
useAtom(undefined)
throwsInvalid value used as weak map key
Check List
pnpm run prettier
for formatting code and docs