Is it possible to get createAsync to revaluate/ refetch data like createResource?

I see the example here but I'm still not understanding it
GitHub
GitHub - solidjs/solid-router: A universal router for Solid inspire...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
7 Replies
Birk Skyum
Birk Skyum2y ago
If you have a cache function, and use it inside a createAsync, then should be able to do a cache revalidate, and my understanding is that it will trigger an update of the createAsync
Birk Skyum
Birk Skyum2y ago
GitHub
GitHub - solidjs/solid-router: A universal router for Solid inspire...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
Lo | Building Dromo
I read that but don't understand how or what trigger the revalidate? Would you be able to give me an example?
Birk Skyum
Birk Skyum2y ago
Yes, so you can import {revalidate} from the @solidjs/router
// say `getUser` is a cache
getUser.key;

// which is used in a createAsync:
const user = createAsync(() => getUser(props.params.id));

// revalidate(key?: string | string[] | void);
await revalidate(getUser.key);
// say `getUser` is a cache
getUser.key;

// which is used in a createAsync:
const user = createAsync(() => getUser(props.params.id));

// revalidate(key?: string | string[] | void);
await revalidate(getUser.key);
Lo | Building Dromo
ah it's an actual function got it! Thank you
Birk Skyum
Birk Skyum2y ago
When you've tried, let me know if it works for you
Lo | Building Dromo
I ended up not needing to refetch because I could use the data in the ui to get the value I needed. (I was added data to a list and was thinking of using refetch/ revalidate to get the new number of items in the list but its faster just to add the new item to the existing length of list to get the total @Birk Skyum Thank you for you're help!

Did you find this page helpful?