Skip to content

Is there an API that can refresh a specific atom? #504

Closed Answered by dai-shi
ivanjeremic asked this question in General
Discussion options

You must be logged in to vote

you can use to reset the state?

It's just handy. Not necessary.

What I really meant is async data when you fetch something from an API.

Okay, async or not, the derived atom can't be reset.
In such use cases, I'd create a new atom, or we can now store a promise as an atom value.
Hm, if you just need to refetch, you could add another dependency.

const version = atom(0)
const data = atom(async (get) => {
  get(version)
  const response = await fetch(...)
  return response.json()
})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ivanjeremic
Comment options

@dai-shi
Comment options

Answer selected by ivanjeremic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants