question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async set atom remains cached

See original GitHub issue

I have an async atom that looks like follows

export const someAsyncAtom = atom(
    async (get) => {
        const {data} = await getData();
        return data;
    },
    async (get, set, update) => {
        if (update) {
            set(someAsyncAtom, update);
        } else {
            const {data} = await getData();
            set(someAsyncAtom, data);
        }
    }
);

Now up until v0.16.8 if I wanted to imperatively refresh my data I could use something like

const updateData = useUpdateAtom(someAsyncAtom)

However starting with v.0.16.9 after calling updateData every component that has

const data = useAtomValue(someAsyncAtom)

has now stale data that dates back to before calling the imperative refresh. Any ideas? This is a breaking change for our application.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:23 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
Ding-Fancommented, May 18, 2022

I’ll link the document here to save others time 😃

https://jotai.org/docs/advanced-recipes/atom-creators#atom-with-refresh

1reaction
dai-shicommented, Jun 21, 2021

It looks good. You are not really using the power of atomWithDefault in the example, are you? Yeah, you may want to open a new issue or discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous Data Queries - Recoil
Asynchronous Example​​​ The results are cached, so the query will only execute once per unique input. The interface of the selector is the...
Read more >
Prefetch and cache chained async state? #390 - GitHub
Hello, I'm using useRecoilValueLoadable with async selectors, and have a chain of selectors that look something like this: atom --> async ...
Read more >
Async — Jotai, primitive and flexible state management for ...
Using async atoms, you gain access to real-world data while still managing them directly from your atoms and with incredible ease. We can...
Read more >
Make a java completable future cache atomic - Stack Overflow
I'm going leave it here just in case it becomes useful for somebody else. public class AsyncCache { ExecutorService executor = Executors.
Read more >
Exploring Asynchronous Requests in Recoil - AppSignal Blog
In async requests, this becomes critically important because responses can be cached. When selector functions get parameter dependencies, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found