Skip to content
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

How to return a DefaultValue in read of useRecoilSync? #1824

Closed
ci7lus opened this issue May 28, 2022 · 2 comments
Closed

How to return a DefaultValue in read of useRecoilSync? #1824

ci7lus opened this issue May 28, 2022 · 2 comments

Comments

@ci7lus
Copy link

ci7lus commented May 28, 2022

Hi, I am referencing an external source in useRecoilSync's read, but when it returns undefined or DefaultValue it does not fall back to the default value.

Code

export const testAtom = atom<boolean>({
  key: `test`,
  default: true,
  effects: [
    syncEffect({ storeKey:"store-key", refine: $.boolean() }),
  ],
})

Try1

  useRecoilSync({
    storeKey: "store-key",
    read: (key) => {
      return store.get(key) || undefined
    },

Try2

  useRecoilSync({
    storeKey: "store-key",
    read: (key) => {
      return store.get(key) || DefaultValue
    },

Occur

[<root>]: value is not a boolean

Environment

  • recoil 0.7.3-alpha.2
  • recoil-sync 0.0.1-alpha.2
@ci7lus ci7lus changed the title DefaultValue in read of useRecoilSync How to return a DefaultValue in read of useRecoilSync May 29, 2022
@ci7lus ci7lus changed the title How to return a DefaultValue in read of useRecoilSync How to return a DefaultValue in read of useRecoilSync? May 29, 2022
@drarmstr
Copy link
Contributor

DefaultValue is the class, so try creating a new instance of that class with new DefaultValue().

@ci7lus
Copy link
Author

ci7lus commented Jun 1, 2022

@drarmstr Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants