jotai icon indicating copy to clipboard operation
jotai copied to clipboard

Throw error on `useAtom(undefined)` or `useAtom(null)`

Open kevinschaich opened this issue 1 year ago • 4 comments

Related Bug Reports or Discussions

Fixes #2777

Summary

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

Check List

  • [x] pnpm run prettier for formatting code and docs

kevinschaich avatar Oct 19 '24 21:10 kevinschaich

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jotai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 11, 2024 10:58am

vercel[bot] avatar Oct 19 '24 21:10 vercel[bot]

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.

codesandbox-ci[bot] avatar Oct 19 '24 21:10 codesandbox-ci[bot]

Nice, I like the second one @dai-shi. Simple and won't break apps in production.

kevinschaich avatar Oct 19 '24 22:10 kevinschaich

LiveCodes Preview in LiveCodes

Latest commit: fceda43586e0e02ad25821260a30006449a41c43
Last updated: Nov 11, 2024 10:58am (UTC)

Playground Link
React demo https://livecodes.io?x=id/2T87KR47E

See documentations for usage instructions.

github-actions[bot] avatar Oct 19 '24 22:10 github-actions[bot]

@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

kevinschaich avatar Oct 21 '24 18:10 kevinschaich

I added two commits illustrating two ideas. Do they work as expected?

dai-shi avatar Oct 23 '24 15:10 dai-shi

@kevinschaich whenever you have time.

dai-shi avatar Nov 05 '24 07:11 dai-shi

Hey @dai-shi, changes working as expected for me. I think this is OK to move forward with.

kevinschaich avatar Nov 10 '24 23:11 kevinschaich